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


Ignore:
Timestamp:
Oct 31, 2007, 3:54:37 AM (18 years ago)
Author:
oliver
Message:

Remove SourceCodeElement class and replaced with a Vector for a 0.8% gain on sunspider

Reviewed by Maciej

File:
1 edited

Legend:

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

    r27255 r27308  
    26212621}
    26222622
     2623// ------------------------------ Helper functions for handling Vectors of StatementNode -------------------------------
     2624
     2625static inline void statementListPushFIFO(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks::NodeStack& stack)
     2626{
     2627    for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr >= statements.begin(); ptr--)
     2628        stack.append((*ptr).get());
     2629}
     2630
     2631static inline void statementListGetDeclarations(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks& stacks)
     2632{
     2633    for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr >= statements.begin(); ptr--)
     2634        if ((*ptr)->mayHaveDeclarations())
     2635            stacks.nodeStack.append((*ptr).get());
     2636}
     2637
     2638static inline Node* statementListInitializeDeclarationStacks(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks::NodeStack& stack)
     2639{
     2640    for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr >= statements.begin(); ptr--)
     2641        if ((*ptr)->mayHaveDeclarations())
     2642             stack.append((*ptr).get());
     2643    if (!stack.size())
     2644        return 0;
     2645    Node* n = stack.last();
     2646    stack.removeLast();
     2647    return n;
     2648}
     2649
     2650static inline Node* statementListInitializeVariableAccessStack(Vector<RefPtr<StatementNode> >& statements, DeclarationStacks::NodeStack& stack)
     2651{
     2652    for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.end() - 1; ptr != statements.begin(); ptr--)
     2653        stack.append((*ptr).get());
     2654    return statements[0].get();
     2655}
     2656
     2657static inline Completion statementListExecute(Vector<RefPtr<StatementNode> >& statements, ExecState *exec)
     2658{
     2659    JSValue* v = 0;
     2660    Completion c(Normal);
     2661    const Vector<RefPtr<StatementNode> >::iterator end = statements.end();
     2662    for (Vector<RefPtr<StatementNode> >::iterator ptr = statements.begin(); ptr != end; ptr++) {
     2663        c = (*ptr)->execute(exec);
     2664       
     2665        if (JSValue* v2 = c.value())
     2666            v = v2;
     2667        c.setValue(v);
     2668       
     2669        if (c.complType() != Normal)
     2670            return c;
     2671    }
     2672    return c;
     2673}
     2674   
    26232675// ------------------------------ BlockNode ------------------------------------
    26242676
    26252677void BlockNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
    26262678{
    2627     if (source)
    2628         nodeStack.append(source.get());
    2629 }
    2630 
    2631 BlockNode::BlockNode(SourceElementsNode* s)
    2632 {
    2633   if (s) {
     2679    if (m_children)
     2680        statementListPushFIFO(*m_children, nodeStack);
     2681}
     2682
     2683BlockNode::BlockNode(Vector<RefPtr<StatementNode> >* children)
     2684{
     2685  if (children) {
    26342686    m_mayHaveDeclarations = true;
    2635     source = s;
    2636     setLoc(s->firstLine(), s->lastLine());
    2637   } else {
    2638     source = 0;
     2687    m_children.set(children);
     2688    setLoc(children->at(0)->firstLine(), children->at(children->size() - 1)->lastLine());
    26392689  }
    26402690}
     
    26422692void BlockNode::getDeclarations(DeclarationStacks& stacks)
    26432693{
    2644     ASSERT(source && source->mayHaveDeclarations());
    2645     stacks.nodeStack.append(source.get());
     2694    ASSERT(m_children);
     2695    statementListGetDeclarations(*m_children, stacks);
    26462696}
    26472697
     
    26492699Completion BlockNode::execute(ExecState *exec)
    26502700{
    2651   if (!source)
     2701  if (!m_children)
    26522702    return Completion(Normal);
    26532703
    2654   return source->execute(exec);
     2704  return statementListExecute(*m_children, exec);
    26552705}
    26562706
     
    31033153  return res;
    31043154}
    3105 
     3155   
    31063156// ------------------------------ CaseClauseNode -------------------------------
    31073157
     
    31103160    if (expr)
    31113161        nodeStack.append(expr.get());
    3112     if (source)
    3113         nodeStack.append(source.get());
     3162    if (m_children)
     3163        statementListPushFIFO(*m_children, nodeStack);
    31143164}
    31153165
    31163166void CaseClauseNode::getDeclarations(DeclarationStacks& stacks)
    31173167{
    3118     if (source && source->mayHaveDeclarations())
    3119         stacks.nodeStack.append(source.get());
     3168    if (m_children)
     3169        statementListGetDeclarations(*m_children, stacks);
    31203170}
    31213171
     
    31323182Completion CaseClauseNode::evalStatements(ExecState *exec)
    31333183{
    3134   if (source)
    3135     return source->execute(exec);
     3184  if (m_children)
     3185    return statementListExecute(*m_children, exec);
    31363186  else
    31373187    return Completion(Normal, jsUndefined());
     
    33953445// ------------------------------ FunctionBodyNode -----------------------------
    33963446
    3397 FunctionBodyNode::FunctionBodyNode(SourceElementsNode* s)
    3398     : BlockNode(s)
     3447FunctionBodyNode::FunctionBodyNode(Vector<RefPtr<StatementNode> > *children)
     3448    : BlockNode(children)
    33993449    , m_sourceURL(Lexer::curr()->sourceURL())
    34003450    , m_sourceId(Parser::sid)
     
    34083458void FunctionBodyNode::initializeDeclarationStacks(ExecState* exec)
    34093459{
    3410     Node* node = source.get();
     3460    if (!m_children)
     3461        return;
     3462
     3463    DeclarationStacks::NodeStack nodeStack;
     3464    DeclarationStacks stacks(exec, nodeStack, m_varStack, m_functionStack);
     3465    Node* node = statementListInitializeDeclarationStacks(*m_children, nodeStack);
    34113466    if (!node)
    34123467        return;
    3413 
    3414     DeclarationStacks::NodeStack nodeStack;
    3415     DeclarationStacks stacks(exec, nodeStack, m_varStack, m_functionStack);
    34163468   
    34173469    while (true) {
     
    34503502void FunctionBodyNode::optimizeVariableAccess()
    34513503{
    3452     Node* node = source.get();
     3504    if (!m_children)
     3505        return;
     3506
     3507    DeclarationStacks::NodeStack nodeStack;
     3508    Node* node = statementListInitializeVariableAccessStack(*m_children, nodeStack);
    34533509    if (!node)
    34543510        return;
    3455 
    3456     DeclarationStacks::NodeStack nodeStack;
    3457 
     3511   
    34583512    while (true) {
    34593513        node->optimizeVariableAccess(this, nodeStack);
     
    36323686}
    36333687
    3634 // ------------------------------ SourceElementsNode ---------------------------
    3635 
    3636 int SourceElementsNode::count = 0;
    3637 
    3638 SourceElementsNode::SourceElementsNode(StatementNode* s1)
    3639   : node(s1)
    3640 {
    3641     m_mayHaveDeclarations = true;
    3642     setLoc(s1->firstLine(), s1->lastLine());
    3643 }
    3644 
    3645 SourceElementsNode::SourceElementsNode(SourceElementsNode* s1, StatementNode* s2)
    3646   : node(s2)
    3647 {
    3648   m_mayHaveDeclarations = true;
    3649   s1->next = this;
    3650   setLoc(s1->firstLine(), s2->lastLine());
    3651 }
    3652 
    3653 void SourceElementsNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
    3654 {
    3655     if (next)
    3656         nodeStack.append(next.get());
    3657     nodeStack.append(node.get());
    3658 }
    3659 
    3660 void SourceElementsNode::getDeclarations(DeclarationStacks& stacks)
    3661 {
    3662     if (next && next->mayHaveDeclarations())
    3663         stacks.nodeStack.append(next.get());
    3664     if (node->mayHaveDeclarations())
    3665         stacks.nodeStack.append(node.get());
    3666 }
    3667 
    3668 // ECMA 14
    3669 Completion SourceElementsNode::execute(ExecState *exec)
    3670 {
    3671   JSValue* v = 0;
    3672   SourceElementsNode* n = this;
    3673   while (1) {
    3674     Completion c = n->node->execute(exec);
    3675 
    3676     if (JSValue* v2 = c.value())
    3677       v = v2;
    3678     c.setValue(v);
    3679 
    3680     if (c.complType() != Normal)
    3681         return c;
    3682 
    3683     n = n->next.get();
    3684     if (!n)
    3685         return c;
    3686   }
    3687 }
    3688 
    3689 ProgramNode::ProgramNode(SourceElementsNode* s)
    3690     : FunctionBodyNode(s)
    3691 {
    3692 }
    3693 
    3694 }
     3688ProgramNode::ProgramNode(Vector<RefPtr<StatementNode> >* children)
     3689    : FunctionBodyNode(children)
     3690{
     3691}
     3692
     3693}
Note: See TracChangeset for help on using the changeset viewer.