Skip to content

Commit

Permalink
[JSC] Do not use temp RegisterID when initializing local FunctionDecl…
Browse files Browse the repository at this point in the history
…aration

https://bugs.webkit.org/show_bug.cgi?id=270665
rdar://124236096

Reviewed by Justin Michaud.

Let's avoid unnecessary mov. We can initialize local RegisterID directly for FunctionDeclaration.

* Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp:
(JSC::BytecodeGenerator::generate):

Canonical link: https://commits.webkit.org/275818@main
  • Loading branch information
Constellation committed Mar 8, 2024
1 parent 70e260f commit 347b11e
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,22 @@ ParserError BytecodeGenerator::generate(unsigned& size)

{
bool shouldHoistInEval = m_codeType == EvalCode && !m_ecmaMode.isStrict();
RefPtr<RegisterID> temp = newTemporary();
RefPtr<RegisterID> topLevelScope;
for (auto functionPair : m_functionsToInitialize) {
FunctionMetadataNode* metadata = functionPair.first;
FunctionVariableType functionType = functionPair.second;
emitNewFunction(temp.get(), metadata);
if (functionType == NormalFunctionVariable)
initializeVariable(variable(metadata->ident()), temp.get());
else if (functionType == TopLevelFunctionVariable) {
if (functionType == NormalFunctionVariable) {
Variable var = variable(metadata->ident());
if (RegisterID* local = var.local())
emitNewFunction(local, metadata);
else {
RefPtr<RegisterID> temp = newTemporary();
emitNewFunction(temp.get(), metadata);
initializeVariable(var, temp.get());
}
} else if (functionType == TopLevelFunctionVariable) {
RefPtr<RegisterID> temp = newTemporary();
emitNewFunction(temp.get(), metadata);
if (!topLevelScope) {
// We know this will resolve to the top level scope or global object because our parser/global initialization code
// doesn't allow let/const/class variables to have the same names as functions.
Expand Down

0 comments on commit 347b11e

Please sign in to comment.