Changeset 27799 in webkit for trunk/JavaScriptCore/kjs/nodes.cpp


Ignore:
Timestamp:
Nov 14, 2007, 2:59:29 PM (18 years ago)
Author:
[email protected]
Message:

Reviewed by Eric Seidel.


Cleaned up the JavaScript grammar a bit.


  1. Changed BlockNode to always hold a child vector (which may be empty), eliminating a few NULL-check branches in the common execution case.


  1. Changed the Block production to correctly report its starting and ending line numbers to the debugger. (It used to report its ending line as its starting line.) Also, removed duplicate line-reporting code inside the BlockNode constructor.


  1. Moved curly braces up from FunctionBody production into parent productions. (I had to move the line number reporting code, too, since it depends on the location of the curly braces.) This matches the ECMA spec more closely, and makes some future changes I plan easier.


  1. Fixed statementList* convenience functions to deal appropriately with empty Vectors.

SunSpider reports a small and statistically insignificant speedup.

  • kjs/grammar.y:
  • kjs/nodes.cpp: (KJS::statementListPushFIFO): (KJS::statementListGetDeclarations): (KJS::statementListInitializeDeclarationStack): (KJS::statementListInitializeVariableAccessStack): (KJS::BlockNode::BlockNode): (KJS::BlockNode::optimizeVariableAccess): (KJS::BlockNode::getDeclarations): (KJS::BlockNode::execute): (KJS::FunctionBodyNode::initializeDeclarationStacks): (KJS::FunctionBodyNode::optimizeVariableAccess):
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/nodes.cpp

    r27749 r27799  
    35973597static inline void statementListPushFIFO(SourceElements& statements, DeclarationStacks::NodeStack& stack)
    35983598{
    3599     for (SourceElements::iterator ptr = statements.end() - 1; ptr >= statements.begin(); --ptr)
    3600         stack.append((*ptr).get());
     3599    SourceElements::iterator it = statements.end();
     3600    SourceElements::iterator begin = statements.begin();
     3601    while (it != begin) {
     3602        --it;
     3603        stack.append((*it).get());
     3604    }
    36013605}
    36023606
    36033607static inline void statementListGetDeclarations(SourceElements& statements, DeclarationStacks& stacks)
    36043608{
    3605     for (SourceElements::iterator ptr = statements.end() - 1; ptr >= statements.begin(); --ptr)
    3606         if ((*ptr)->mayHaveDeclarations())
    3607             stacks.nodeStack.append((*ptr).get());
    3608 }
    3609 
    3610 static inline Node* statementListInitializeDeclarationStacks(SourceElements& statements, DeclarationStacks::NodeStack& stack)
    3611 {
    3612     for (SourceElements::iterator ptr = statements.end() - 1; ptr >= statements.begin(); --ptr)
    3613         if ((*ptr)->mayHaveDeclarations())
    3614              stack.append((*ptr).get());
     3609    SourceElements::iterator it = statements.end();
     3610    SourceElements::iterator begin = statements.begin();
     3611    while (it != begin) {
     3612        --it;
     3613        if ((*it)->mayHaveDeclarations())
     3614            stacks.nodeStack.append((*it).get());
     3615    }
     3616}
     3617
     3618static inline Node* statementListInitializeDeclarationStack(SourceElements& statements, DeclarationStacks::NodeStack& stack)
     3619{
     3620    ASSERT(!stack.size()); // Otherwise, the removeLast() call might remove someone else's node.
     3621   
     3622    SourceElements::iterator it = statements.end();
     3623    SourceElements::iterator begin = statements.begin();
     3624   
     3625    while (it != begin) {
     3626        --it;
     3627        if ((*it)->mayHaveDeclarations())
     3628             stack.append((*it).get());
     3629    }
     3630
    36153631    if (!stack.size())
    36163632        return 0;
     3633
    36173634    Node* n = stack.last();
    36183635    stack.removeLast();
     
    36223639static inline Node* statementListInitializeVariableAccessStack(SourceElements& statements, DeclarationStacks::NodeStack& stack)
    36233640{
    3624     for (SourceElements::iterator ptr = statements.end() - 1; ptr != statements.begin(); --ptr)
    3625         stack.append((*ptr).get());
    3626     return statements[0].get();
     3641    if (!statements.size())
     3642        return 0;
     3643
     3644    SourceElements::iterator it = statements.end();
     3645    SourceElements::iterator begin = statements.begin();
     3646    SourceElements::iterator beginPlusOne = begin + 1;
     3647   
     3648    while (it != beginPlusOne) {
     3649        --it;
     3650        stack.append((*it).get());
     3651    }
     3652
     3653    return (*begin).get();
    36273654}
    36283655
     
    36473674// ------------------------------ BlockNode ------------------------------------
    36483675
    3649 void BlockNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
    3650 {
    3651     if (m_children)
    3652         statementListPushFIFO(*m_children, nodeStack);
    3653 }
    3654 
    36553676BlockNode::BlockNode(SourceElements* children)
    36563677{
    3657   if (children) {
     3678    ASSERT(children);
    36583679    m_mayHaveDeclarations = true;
    36593680    m_children.set(children);
    3660     setLoc(children->at(0)->firstLine(), children->at(children->size() - 1)->lastLine());
    3661   }
     3681}
     3682
     3683void BlockNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
     3684{
     3685    statementListPushFIFO(*m_children, nodeStack);
    36623686}
    36633687
    36643688void BlockNode::getDeclarations(DeclarationStacks& stacks)
    36653689{
    3666     ASSERT(m_children);
    36673690    statementListGetDeclarations(*m_children, stacks);
    36683691}
     
    36713694Completion BlockNode::execute(ExecState *exec)
    36723695{
    3673   if (!m_children)
    3674     return Completion(Normal);
    3675 
    3676   return statementListExecute(*m_children, exec);
     3696    return statementListExecute(*m_children, exec);
    36773697}
    36783698
     
    44044424void FunctionBodyNode::initializeDeclarationStacks(ExecState* exec)
    44054425{
    4406     if (!m_children)
    4407         return;
    4408 
    44094426    DeclarationStacks::NodeStack nodeStack;
    44104427    DeclarationStacks stacks(exec, nodeStack, m_varStack, m_functionStack);
    4411     Node* node = statementListInitializeDeclarationStacks(*m_children, nodeStack);
     4428    Node* node = statementListInitializeDeclarationStack(*m_children, nodeStack);
    44124429    if (!node)
    44134430        return;
     
    44484465void FunctionBodyNode::optimizeVariableAccess()
    44494466{
    4450     if (!m_children)
    4451         return;
    4452 
    44534467    DeclarationStacks::NodeStack nodeStack;
    44544468    Node* node = statementListInitializeVariableAccessStack(*m_children, nodeStack);
Note: See TracChangeset for help on using the changeset viewer.