Skip to content

Commit 9f770b1

Browse files
committed
[JSC] Add a fast path to Parser::useVariable
https://bugs.webkit.org/show_bug.cgi?id=321716 rdar://184855343 Reviewed by Yijia Huang. Parser::useVariable adds a variable to the top set of the m_usedVariables stack. It's not uncommon for the same variable to be added repeatedly, so it helps to remember the last added variable and skip the extra work if it gets added again. Covered by existing tests. Canonical link: https://commits.webkit.org/319191@main
1 parent 60019eb commit 9f770b1

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

‎Source/JavaScriptCore/parser/Parser.h‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -650,6 +650,13 @@ struct Scope {
650650
void useVariable(UniquedStringImpl* impl, bool isEval)
651651
{
652652
m_usesEval |= isEval;
653+
if (impl == m_lastAddedUsedVariable) {
654+
// A failure indicates that m_usedVariables was changed (a set added or removed)
655+
// without clearing m_lastAddedUsedVariable.
656+
ASSERT(m_usedVariables.last().contains(impl));
657+
return;
658+
}
659+
m_lastAddedUsedVariable = impl;
653660
m_usedVariables.last().add(impl);
654661
}
655662
void usePrivateName(const Identifier& ident)
@@ -659,9 +666,17 @@ struct Scope {
659666

660667
void setUsesImportMeta() { m_usesImportMeta = true; }
661668

662-
void pushUsedVariableSet() { m_usedVariables.append(UniquedStringImplPtrSet()); }
669+
void pushUsedVariableSet()
670+
{
671+
m_usedVariables.append(UniquedStringImplPtrSet());
672+
m_lastAddedUsedVariable = nullptr;
673+
}
663674
size_t currentUsedVariablesSize() { return m_usedVariables.size(); }
664-
void revertToPreviousUsedVariables(size_t size) { m_usedVariables.resize(size); }
675+
void revertToPreviousUsedVariables(size_t size)
676+
{
677+
m_usedVariables.resize(size);
678+
m_lastAddedUsedVariable = nullptr;
679+
}
665680

666681
void setNeedsFullActivation() { m_needsFullActivation = true; }
667682
bool needsFullActivation() const { return m_needsFullActivation; }
@@ -1031,6 +1046,7 @@ struct Scope {
10311046
EvalContextType m_evalContextType { EvalContextType::None };
10321047
DerivedContextType m_derivedContextType { DerivedContextType::None };
10331048

1049+
UniquedStringImpl* m_lastAddedUsedVariable { nullptr };
10341050
Vector<UniquedStringImplPtrSet, 6> m_usedVariables;
10351051

10361052
static void verifyLayout();

0 commit comments

Comments
 (0)