Skip to content

Commit bf38e2a

Browse files
author
Irina Yatsenko
committed
[MERGE #5135 @irinayat-MS] Mark strings used by 'in' operator as property names
Merge pull request #5135 from irinayat-MS:PropString_In_Operator Micro optimization to create PropertyStrings for strings that are known to be property names (because they are being used as such in 'in' operator). Targeted benchmarks show x2 improvement (runtime), telemetry from crawler registered no difference but also showed that the optimization's trade off of using more memory isn't a concern (same amount of strings is registered as properties with or without the optimization). Thus, the fix has a potential of improving a subset of specific usage patterns without any known broard drawbacks, so it was decided to take it.
2 parents 6992479 + a845407 commit bf38e2a

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

lib/Parser/Parse.cpp

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8848,11 +8848,14 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
88488848
break;
88498849
}
88508850
}
8851-
else
8851+
else // a binary operator
88528852
{
8853+
ParseNode* pnode1 = pnode;
8854+
88538855
// Parse the operand, make a new node, and look for more
88548856
IdentToken token;
8855-
pnodeT = ParseExpr<buildAST>(opl, NULL, fAllowIn, FALSE, pNameHint, &hintLength, &hintOffset, &token, false, nullptr, plastRParen);
8857+
ParseNode* pnode2 = ParseExpr<buildAST>(
8858+
opl, nullptr, fAllowIn, FALSE, pNameHint, &hintLength, &hintOffset, &token, false, nullptr, plastRParen);
88568859

88578860
// Detect nested function escapes of the pattern "o.f = function(){...}" or "o[s] = function(){...}".
88588861
// Doing so in the parser allows us to disable stack-nested-functions in common cases where an escape
@@ -8864,36 +8867,42 @@ ParseNodePtr Parser::ParseExpr(int oplMin,
88648867

88658868
if (buildAST)
88668869
{
8867-
pnode = CreateBinNode(nop, pnode, pnodeT);
8868-
Assert(pnode->AsParseNodeBin()->pnode2 != NULL);
8869-
if (pnode->AsParseNodeBin()->pnode2->nop == knopFncDecl)
8870+
Assert(pnode2 != nullptr);
8871+
if (pnode2->nop == knopFncDecl)
88708872
{
88718873
Assert(hintLength >= hintOffset);
8872-
pnode->AsParseNodeBin()->pnode2->AsParseNodeFnc()->hint = pNameHint;
8873-
pnode->AsParseNodeBin()->pnode2->AsParseNodeFnc()->hintLength = hintLength;
8874-
pnode->AsParseNodeBin()->pnode2->AsParseNodeFnc()->hintOffset = hintOffset;
8874+
pnode2->AsParseNodeFnc()->hint = pNameHint;
8875+
pnode2->AsParseNodeFnc()->hintLength = hintLength;
8876+
pnode2->AsParseNodeFnc()->hintOffset = hintOffset;
88758877

8876-
if (pnode->AsParseNodeBin()->pnode1->nop == knopDot)
8878+
if (pnode1->nop == knopDot)
88778879
{
8878-
pnode->AsParseNodeBin()->pnode2->AsParseNodeFnc()->isNameIdentifierRef = false;
8880+
pnode2->AsParseNodeFnc()->isNameIdentifierRef = false;
88798881
}
8880-
else if (pnode->AsParseNodeBin()->pnode1->nop == knopName)
8882+
else if (pnode1->nop == knopName)
88818883
{
8882-
PidRefStack *pidRef = pnode->AsParseNodeBin()->pnode1->AsParseNodeName()->pid->GetTopRef();
8884+
PidRefStack *pidRef = pnode1->AsParseNodeName()->pid->GetTopRef();
88838885
pidRef->isFuncAssignment = true;
88848886
}
88858887
}
8886-
if (pnode->AsParseNodeBin()->pnode2->nop == knopClassDecl && pnode->AsParseNodeBin()->pnode1->nop == knopDot)
8888+
else if (pnode2->nop == knopClassDecl && pnode1->nop == knopDot)
88878889
{
8888-
Assert(pnode->AsParseNodeBin()->pnode2->AsParseNodeClass()->pnodeConstructor);
8890+
Assert(pnode2->AsParseNodeClass()->pnodeConstructor);
88898891

8890-
if (!pnode->AsParseNodeBin()->pnode2->AsParseNodeClass()->pnodeConstructor->pid)
8892+
if (!pnode2->AsParseNodeClass()->pnodeConstructor->pid)
88918893
{
8892-
pnode->AsParseNodeBin()->pnode2->AsParseNodeClass()->pnodeConstructor->isNameIdentifierRef = false;
8894+
pnode2->AsParseNodeClass()->pnodeConstructor->isNameIdentifierRef = false;
88938895
}
88948896
}
8897+
else if (pnode1->nop == knopName && nop == knopIn)
8898+
{
8899+
PidRefStack* pidRef = pnode1->AsParseNodeName()->pid->GetTopRef();
8900+
pidRef->SetIsUsedInLdElem(true);
8901+
}
8902+
8903+
pnode = CreateBinNode(nop, pnode1, pnode2);
88958904
}
8896-
pNameHint = NULL;
8905+
pNameHint = nullptr;
88978906
}
88988907
}
88998908

0 commit comments

Comments
 (0)