Skip to content

Commit 41848d9

Browse files
committed
Stop using Vector::unsafeAppendWithoutCapacityCheck() in WasmBBQJIT.cpp
https://bugs.webkit.org/show_bug.cgi?id=264646 Reviewed by Darin Adler. * Source/JavaScriptCore/wasm/WasmBBQJIT.cpp: (JSC::Wasm::BBQJIT::addSwitch): Canonical link: https://commits.webkit.org/270622@main
1 parent 6b87ac8 commit 41848d9

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

Source/JavaScriptCore/wasm/WasmBBQJIT.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7559,28 +7559,26 @@ class BBQJIT {
75597559

75607560
constexpr unsigned minCasesForTable = 7;
75617561
if (minCasesForTable <= targets.size()) {
7562-
Vector<Box<CCallHelpers::Label>> labels;
7563-
labels.reserveInitialCapacity(targets.size());
75647562
auto* jumpTable = m_callee.addJumpTable(targets.size());
75657563
auto fallThrough = m_jit.branch32(RelationalCondition::AboveOrEqual, wasmScratchGPR, TrustedImm32(targets.size()));
75667564
m_jit.zeroExtend32ToWord(wasmScratchGPR, wasmScratchGPR);
75677565
m_jit.lshiftPtr(TrustedImm32(3), wasmScratchGPR);
75687566
m_jit.addPtr(TrustedImmPtr(jumpTable->data()), wasmScratchGPR);
75697567
m_jit.farJump(Address(wasmScratchGPR), JSSwitchPtrTag);
75707568

7571-
for (unsigned index = 0; index < targets.size(); ++index) {
7572-
Box<CCallHelpers::Label> label = Box<CCallHelpers::Label>::create(m_jit.label());
7573-
labels.unsafeAppendWithoutCapacityCheck(label);
7574-
bool isCodeEmitted = currentControlData().addExit(*this, targets[index]->targetLocations(), results);
7569+
auto labels = WTF::map(targets, [&](auto& target) {
7570+
auto label = Box<CCallHelpers::Label>::create(m_jit.label());
7571+
bool isCodeEmitted = currentControlData().addExit(*this, target->targetLocations(), results);
75757572
if (isCodeEmitted)
7576-
targets[index]->addBranch(m_jit.jump());
7573+
target->addBranch(m_jit.jump());
75777574
else {
75787575
// It is common that we do not need to emit anything before jumping to the target block.
75797576
// In that case, we put Box<Label> which will be filled later when the end of the block is linked.
75807577
// We put direct jump to that block in the link task.
7581-
targets[index]->addLabel(WTFMove(label));
7578+
target->addLabel(Box { label });
75827579
}
7583-
}
7580+
return label;
7581+
});
75847582

75857583
m_jit.addLinkTask([labels = WTFMove(labels), jumpTable](LinkBuffer& linkBuffer) {
75867584
for (unsigned index = 0; index < labels.size(); ++index)

0 commit comments

Comments
 (0)