Skip to content

Commit a544a21

Browse files
committed
Use faster alternatives to Vector::resize() when possible
https://bugs.webkit.org/show_bug.cgi?id=265423 Reviewed by Darin Adler. Use faster alternatives to Vector::resize() when possible. It involves calling directly Vector::shrink(), Vector::grow() or a Vector constructor. * Source/JavaScriptCore/b3/B3EliminateDeadCode.cpp: (JSC::B3::eliminateDeadCodeImpl): * Source/JavaScriptCore/b3/B3ReduceStrength.cpp: * Source/JavaScriptCore/b3/air/AirAllocateRegistersByGraphColoring.cpp: * Source/JavaScriptCore/bytecode/BytecodeDumper.cpp: (JSC::CodeBlockBytecodeDumper<Block>::dumpGraph): * Source/JavaScriptCore/bytecode/BytecodeGeneratorification.cpp: (JSC::BytecodeGeneratorification::BytecodeGeneratorification): (JSC::BytecodeGeneratorification::storageForGeneratorLocal): * Source/JavaScriptCore/bytecode/InlineCacheCompiler.cpp: (JSC::InlineCacheCompiler::regenerate): * Source/JavaScriptCore/dfg/DFGCPSRethreadingPhase.cpp: (JSC::DFG::CPSRethreadingPhase::freeUnnecessaryNodes): * Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp: * Source/JavaScriptCore/interpreter/ShadowChicken.cpp: (JSC::ShadowChicken::update): * Source/JavaScriptCore/jit/CallFrameShuffleData.cpp: (JSC::CallFrameShuffleData::createForBaselineOrLLIntTailCall): * Source/JavaScriptCore/jit/CallFrameShuffler.h: (JSC::CallFrameShuffler::snapshot const): * Source/JavaScriptCore/runtime/ISO8601.cpp: (JSC::ISO8601::formatTimeZoneOffsetString): (JSC::ISO8601::temporalTimeToString): * Source/JavaScriptCore/runtime/IntlObject.cpp: (JSC::availableCollations): (JSC::availableCurrencies): * Source/JavaScriptCore/runtime/JSGenericTypedArrayViewInlines.h: (JSC::JSGenericTypedArrayView<Adaptor>::sort): * Source/JavaScriptCore/runtime/JSGenericTypedArrayViewPrototypeFunctions.h: (JSC::genericTypedArrayViewProtoFuncSortImpl): * Source/JavaScriptCore/runtime/ObjectConstructorInlines.h: (JSC::objectAssignFast): * Source/JavaScriptCore/runtime/RegExp.cpp: (JSC::RegExp::matchCompareWithInterpreter): * Source/JavaScriptCore/runtime/StringPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::bind): * Source/JavaScriptCore/wasm/WasmFunctionIPIntMetadataGenerator.cpp: (JSC::Wasm::FunctionIPIntMetadataGenerator::addBlankSpace): (JSC::Wasm::FunctionIPIntMetadataGenerator::addRawValue): (JSC::Wasm::FunctionIPIntMetadataGenerator::addLength): (JSC::Wasm::FunctionIPIntMetadataGenerator::addLEB128ConstantInt32AndLength): (JSC::Wasm::FunctionIPIntMetadataGenerator::addCondensedLocalIndexAndLength): (JSC::Wasm::FunctionIPIntMetadataGenerator::addLEB128ConstantAndLengthForType): (JSC::Wasm::FunctionIPIntMetadataGenerator::addLEB128V128Constant): * Source/JavaScriptCore/wasm/WasmFunctionParser.h: (JSC::Wasm::FunctionParser<Context>::parseExpression): * Source/JavaScriptCore/wasm/WasmLLIntGenerator.cpp: (JSC::Wasm::LLIntGenerator::finalize): * Source/WTF/wtf/Liveness.h: (WTF::Liveness::compute): * Source/WTF/wtf/NativePromise.h: * Source/WTF/wtf/text/StringView.h: (WTF::StringView::UpconvertedCharacters::UpconvertedCharacters): * Source/WebCore/Modules/compression/CompressionStreamEncoder.cpp: (WebCore::CompressionStreamEncoder::compress): * Source/WebCore/Modules/compression/DecompressionStreamDecoder.cpp: (WebCore::DecompressionStreamDecoder::decompressZlib): (WebCore::DecompressionStreamDecoder::decompressAppleCompressionFramework): * Source/WebCore/Modules/fetch/FetchHeaders.cpp: (WebCore::FetchHeaders::Iterator::next): * Source/WebCore/Modules/mediastream/RTCRtpSFrameTransformer.cpp: (WebCore::RTCRtpSFrameTransformer::encryptFrame): * Source/WebCore/Modules/mediastream/SFrameUtils.cpp: (WebCore::computeH264PrefixBuffer): * Source/WebCore/Modules/webaudio/AudioWorkletNode.cpp: (WebCore::AudioWorkletNode::AudioWorkletNode): * Source/WebCore/PAL/pal/crypto/commoncrypto/CryptoDigestCommonCrypto.cpp: (PAL::CryptoDigest::computeHash): * Source/WebCore/contentextensions/DFABytecodeCompiler.cpp: (WebCore::ContentExtensions::DFABytecodeCompiler::compile): * Source/WebCore/contentextensions/NFAToDFA.cpp: (WebCore::ContentExtensions::resolveEpsilonClosures): * Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp: (WebCore::WebGLRenderingContextBase::initializeContextState): * Source/WebCore/html/canvas/WebGLTransformFeedback.cpp: (WebCore::WebGLTransformFeedback::WebGLTransformFeedback): * Source/WebCore/html/canvas/WebGLVertexArrayObjectBase.cpp: (WebCore::WebGLVertexArrayObjectBase::WebGLVertexArrayObjectBase): * Source/WebCore/html/parser/HTMLDocumentParserFastPath.cpp: (WebCore::HTMLFastPathParser::scanEscapedText): (WebCore::HTMLFastPathParser::scanTagName): (WebCore::HTMLFastPathParser::scanAttributeName): (WebCore::HTMLFastPathParser::scanEscapedAttributeValue): (WebCore::HTMLFastPathParser::parseAttributes): * Source/WebCore/layout/formattingContexts/flex/FlexLayout.cpp: (WebCore::Layout::FlexLayout::computeMainSizeForFlexItems const): * Source/WebCore/platform/audio/Biquad.cpp: (WebCore::Biquad::Biquad): * Source/WebCore/platform/audio/ReverbConvolverStage.cpp: (WebCore::ReverbConvolverStage::ReverbConvolverStage): * Source/WebCore/platform/graphics/FloatPolygon.cpp: (WebCore::FloatPolygon::FloatPolygon): * Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp: * Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp: (WebCore::EOTHeader::EOTHeader): (WebCore::EOTHeader::appendBigEndianString): * Source/WebCore/platform/image-decoders/bmp/BMPImageReader.cpp: (WebCore::BMPImageReader::processColorTable): * Source/WebCore/platform/image-decoders/jpegxl/JPEGXLImageDecoder.cpp: (WebCore::JPEGXLImageDecoder::processInput): * Source/WebCore/platform/mediarecorder/cocoa/AudioSampleBufferCompressor.mm: (WebCore::AudioSampleBufferCompressor::initAudioConverterForSourceFormatDescription): (WebCore::AudioSampleBufferCompressor::sampleBufferWithNumPackets): (WebCore::AudioSampleBufferCompressor::provideSourceDataNumOutputPackets): * Source/WebCore/rendering/GridMasonryLayout.cpp: (WebCore::GridMasonryLayout::collectMasonryItems): * Source/WebCore/rendering/RenderTableSection.cpp: (WebCore::RenderTableSection::removeRedundantColumns): * Source/WebCore/rendering/shapes/RasterShape.cpp: (WebCore::MarginIntervalGenerator::MarginIntervalGenerator): * Source/WebCore/rendering/shapes/RasterShape.h: (WebCore::RasterShapeIntervals::RasterShapeIntervals): * Source/WebDriver/socket/HTTPParser.cpp: (WebDriver::HTTPParser::abortProcess): * Source/WebKit/NetworkProcess/Notifications/NetworkNotificationManager.cpp: (WebKit::NetworkNotificationManager::NetworkNotificationManager): * Source/WebKit/Shared/mac/AuxiliaryProcessMac.mm: (WebKit::fileContents): * Source/WebKit/UIProcess/Gamepad/UIGamepad.cpp: (WebKit::UIGamepad::UIGamepad): * Source/WebKit/UIProcess/UserMediaProcessManager.cpp: (WebKit::UserMediaProcessManager::willCreateMediaStream): * Source/WebKit/UIProcess/mac/WKTextFinderClient.mm: * Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp: (WebKit::RemoteRenderingBackendProxy::prepareBuffersForDisplay): * Source/WebKit/WebProcess/Gamepad/WebGamepad.cpp: (WebKit::WebGamepad::WebGamepad): * Source/WebKit/WebProcess/Gamepad/WebGamepadProvider.cpp: (WebKit::WebGamepadProvider::gamepadConnected): Canonical link: https://commits.webkit.org/271370@main
1 parent aec79a7 commit a544a21

60 files changed

Lines changed: 131 additions & 148 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Source/JavaScriptCore/b3/B3EliminateDeadCode.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ bool eliminateDeadCodeImpl(Procedure& proc)
9797
changed = true;
9898
}
9999
}
100-
block->values().resize(targetIndex);
100+
block->values().shrink(targetIndex);
101101
}
102102

103103
for (Variable* variable : proc.variables()) {

‎Source/JavaScriptCore/b3/B3ReduceStrength.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3099,7 +3099,7 @@ class ReduceStrength {
30993099
cloneValue(m_value);
31003100

31013101
// Remove the values from the predecessor.
3102-
predecessor->values().resize(startIndex);
3102+
predecessor->values().shrink(startIndex);
31033103

31043104
predecessor->appendNew<Value>(m_proc, Branch, source->origin(), predicate);
31053105
predecessor->setSuccessors(FrequentedBlock(cases[0]), FrequentedBlock(cases[1]));

‎Source/JavaScriptCore/b3/air/AirAllocateRegistersByGraphColoring.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ class AbstractColoringAllocator {
7575
dataLogLn("]");
7676
}
7777

78-
m_adjacencyList.resize(tmpArraySize);
79-
m_moveList.resize(tmpArraySize);
78+
m_adjacencyList.grow(tmpArraySize);
79+
m_moveList.grow(tmpArraySize);
8080
m_isOnSelectStack.ensureSize(tmpArraySize);
8181
m_spillWorklist.ensureSize(tmpArraySize);
8282
}

‎Source/JavaScriptCore/bytecode/BytecodeDumper.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,7 @@ void CodeBlockBytecodeDumper<Block>::dumpGraph(Block* block, const JSInstruction
279279

280280
out.printf("\n");
281281

282-
Vector<Vector<unsigned>> predecessors;
283-
predecessors.resize(graph.size());
282+
Vector<Vector<unsigned>> predecessors(graph.size());
284283
for (auto& block : graph) {
285284
if (block.isEntryBlock() || block.isExitBlock())
286285
continue;

‎Source/JavaScriptCore/bytecode/BytecodeGeneratorification.cpp‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class BytecodeGeneratorification {
7878
auto bytecode = instruction->as<OpYield>();
7979
unsigned liveCalleeLocalsIndex = bytecode.m_yieldPoint;
8080
if (liveCalleeLocalsIndex >= m_yields.size())
81-
m_yields.resize(liveCalleeLocalsIndex + 1);
81+
m_yields.grow(liveCalleeLocalsIndex + 1);
8282
YieldData& data = m_yields[liveCalleeLocalsIndex];
8383
data.point = instruction.offset();
8484
data.argument = bytecode.m_argument;
@@ -147,7 +147,7 @@ class BytecodeGeneratorification {
147147
// It means that, the register can be retrieved even if the immediate previous op_save does not save it.
148148

149149
if (m_storages.size() <= index)
150-
m_storages.resize(index + 1);
150+
m_storages.grow(index + 1);
151151
if (std::optional<Storage> storage = m_storages[index])
152152
return *storage;
153153

‎Source/JavaScriptCore/bytecode/InlineCacheCompiler.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3682,7 +3682,7 @@ AccessGenerationResult InlineCacheCompiler::regenerate(const GCSafeConcurrentJSL
36823682
if (isGenerated)
36833683
poly.m_list[dstIndex++] = WTFMove(someCase);
36843684
}
3685-
poly.m_list.resize(dstIndex);
3685+
poly.m_list.shrink(dstIndex);
36863686

36873687
bool generatedMegamorphicCode = false;
36883688

‎Source/JavaScriptCore/dfg/DFGCPSRethreadingPhase.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class CPSRethreadingPhase : public Phase {
117117

118118
for (unsigned phiIndex = block->phis.size(); phiIndex--;)
119119
m_graph.deleteNode(block->phis[phiIndex]);
120-
block->phis.resize(0);
120+
block->phis.shrink(0);
121121
}
122122
}
123123

‎Source/JavaScriptCore/dfg/DFGObjectAllocationSinkingPhase.cpp‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,8 +1562,7 @@ class ObjectAllocationSinkingPhase : public Phase {
15621562
// Nodes without remaining unmaterialized fields will be
15631563
// materialized first - amongst the remaining unmaterialized
15641564
// nodes
1565-
Vector<Allocation> toMaterialize;
1566-
toMaterialize.resize(escapees.size());
1565+
Vector<Allocation> toMaterialize(escapees.size());
15671566
size_t firstIndex = 0;
15681567
size_t lastIndex = toMaterialize.size();
15691568
auto materializeFirst = [&] (Allocation&& allocation) {

‎Source/JavaScriptCore/interpreter/ShadowChicken.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ void ShadowChicken::update(VM& vm, CallFrame* callFrame)
213213
}
214214
break;
215215
}
216-
m_stack.resize(shadowIndex);
216+
m_stack.shrink(shadowIndex);
217217

218218
if (ShadowChickenInternal::verbose)
219219
dataLog(" Revised stack: ", listDump(m_stack), "\n");

‎Source/JavaScriptCore/jit/CallFrameShuffleData.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ CallFrameShuffleData CallFrameShuffleData::createForBaselineOrLLIntTailCall(cons
9393
shuffleData.numberTagRegister = GPRInfo::numberTagRegister;
9494
#endif
9595
shuffleData.numLocals = bytecode.m_argv - sizeof(CallerFrameAndPC) / sizeof(Register);
96-
shuffleData.args.resize(bytecode.m_argc);
96+
shuffleData.args.grow(bytecode.m_argc);
9797
for (unsigned i = 0; i < bytecode.m_argc; ++i) {
9898
shuffleData.args[i] =
9999
ValueRecovery::displacedInJSStack(

0 commit comments

Comments
 (0)