2007-12-17 Eric Seidel <eric@webkit.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Dec 2007 07:21:20 +0000 (07:21 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 21 Dec 2007 07:21:20 +0000 (07:21 +0000)
        Reviewed by mjs.

        Split IfNode into IfNode and IfElseNode for speedup.
        http://bugs.webkit.org/show_bug.cgi?id=16470

        SunSpider claims this is 1.003x as fast as before.
        (This required running with --runs 15 to get consistent enough results to tell!)

        * kjs/grammar.y:
        * kjs/nodes.cpp:
        (KJS::IfNode::optimizeVariableAccess):
        (KJS::IfNode::execute):
        (KJS::IfNode::getDeclarations):
        (KJS::IfElseNode::optimizeVariableAccess):
        (KJS::IfElseNode::execute):
        (KJS::IfElseNode::getDeclarations):
        * kjs/nodes.h:
        (KJS::IfNode::):
        (KJS::IfElseNode::):
        * kjs/nodes2string.cpp:
        (KJS::IfNode::streamTo):
        (KJS::IfElseNode::streamTo):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@28929 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/grammar.y
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h
JavaScriptCore/kjs/nodes2string.cpp

index 01f6e3b..607ea02 100644 (file)
@@ -1,3 +1,28 @@
+2007-12-17  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by mjs.
+        
+        Split IfNode into IfNode and IfElseNode for speedup.
+        http://bugs.webkit.org/show_bug.cgi?id=16470
+        
+        SunSpider claims this is 1.003x as fast as before.
+        (This required running with --runs 15 to get consistent enough results to tell!)
+
+        * kjs/grammar.y:
+        * kjs/nodes.cpp:
+        (KJS::IfNode::optimizeVariableAccess):
+        (KJS::IfNode::execute):
+        (KJS::IfNode::getDeclarations):
+        (KJS::IfElseNode::optimizeVariableAccess):
+        (KJS::IfElseNode::execute):
+        (KJS::IfElseNode::getDeclarations):
+        * kjs/nodes.h:
+        (KJS::IfNode::):
+        (KJS::IfElseNode::):
+        * kjs/nodes2string.cpp:
+        (KJS::IfNode::streamTo):
+        (KJS::IfElseNode::streamTo):
+
 2007-12-20  Darin Adler  <darin@apple.com>
 
         Reviewed by Sam.
index ca19cf9..4bec3fe 100644 (file)
@@ -801,10 +801,10 @@ ExprStatement:
 
 IfStatement:
     IF '(' Expr ')' Statement %prec IF_WITHOUT_ELSE
-                                        { $$ = createNodeInfo<StatementNode*>(new IfNode($3, $5.m_node, 0), $5.m_varDeclarations, $5.m_funcDeclarations);
+                                        { $$ = createNodeInfo<StatementNode*>(new IfNode($3, $5.m_node), $5.m_varDeclarations, $5.m_funcDeclarations);
                                           DBG($$.m_node, @1, @4); }
   | IF '(' Expr ')' Statement ELSE Statement
-                                        { $$ = createNodeInfo<StatementNode*>(new IfNode($3, $5.m_node, $7.m_node), mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations)); 
+                                        { $$ = createNodeInfo<StatementNode*>(new IfElseNode($3, $5.m_node, $7.m_node), mergeDeclarationLists($5.m_varDeclarations, $7.m_varDeclarations), mergeDeclarationLists($5.m_funcDeclarations, $7.m_funcDeclarations)); 
                                           DBG($$.m_node, @1, @4); }
 ;
 
index a3344fe..3fdb6a4 100644 (file)
@@ -3652,12 +3652,8 @@ JSValue* ExprStatementNode::execute(ExecState* exec)
 
 void IfNode::optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack& nodeStack)
 {
-    if (statement2)
-        nodeStack.append(statement2.get());
-    ASSERT(statement1);
-    nodeStack.append(statement1.get());
-    ASSERT(expr);
-    nodeStack.append(expr.get());
+    nodeStack.append(m_ifBlock.get());
+    nodeStack.append(m_condition.get());
 }
 
 // ECMA 12.5
@@ -3665,19 +3661,32 @@ JSValue* IfNode::execute(ExecState* exec)
 {
     KJS_BREAKPOINT
 
-    bool b = expr->evaluateToBoolean(exec);
+    bool b = m_condition->evaluateToBoolean(exec);
     KJS_CHECKEXCEPTION
 
-    // if ... then
     if (b)
-        return statement1->execute(exec);
+        return m_ifBlock->execute(exec);
+    return exec->setNormalCompletion();
+}
+
+void IfElseNode::optimizeVariableAccess(SymbolTable& table, DeclarationStacks::NodeStack& nodeStack)
+{
+    nodeStack.append(m_elseBlock.get());
+    IfNode::optimizeVariableAccess(table, nodeStack);
+}
 
-    // no else
-    if (!statement2)
-        return exec->setNormalCompletion();
+// ECMA 12.5
+JSValue* IfElseNode::execute(ExecState* exec)
+{
+    KJS_BREAKPOINT;
+
+    bool b = m_condition->evaluateToBoolean(exec);
+    KJS_CHECKEXCEPTION
+
+    if (b)
+        return m_ifBlock->execute(exec);
 
-    // else
-    return statement2->execute(exec);
+    return m_elseBlock->execute(exec);
 }
 
 // ------------------------------ DoWhileNode ----------------------------------
index 0b1f487..895ea12 100644 (file)
@@ -1783,17 +1783,27 @@ namespace KJS {
 
   class IfNode : public StatementNode {
   public:
-    IfNode(ExpressionNode* e, StatementNode *s1, StatementNode *s2) KJS_FAST_CALL
-      : expr(e), statement1(s1), statement2(s2) { }
+    IfNode(ExpressionNode* e, StatementNode *s) KJS_FAST_CALL
+      : m_condition(e), m_ifBlock(s) { }
     virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL;
     virtual JSValue* execute(ExecState*) KJS_FAST_CALL;
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
-  private:
-    RefPtr<ExpressionNode> expr;
-    RefPtr<StatementNode> statement1;
-    RefPtr<StatementNode> statement2;
+  protected:
+    RefPtr<ExpressionNode> m_condition;
+    RefPtr<StatementNode> m_ifBlock;
   };
 
+    class IfElseNode : public IfNode {
+    public:
+        IfElseNode(ExpressionNode* e, StatementNode* ifBlock, StatementNode* elseBlock) KJS_FAST_CALL
+            : IfNode(e, ifBlock), m_elseBlock(elseBlock) { }
+        virtual void optimizeVariableAccess(SymbolTable&, DeclarationStacks::NodeStack&) KJS_FAST_CALL;
+        virtual JSValue* execute(ExecState*) KJS_FAST_CALL;
+        virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
+    private:
+        RefPtr<StatementNode> m_elseBlock;
+    };
+
   class DoWhileNode : public StatementNode {
   public:
     DoWhileNode(StatementNode *s, ExpressionNode* e) KJS_FAST_CALL : statement(s), expr(e) { }
index 63f3f48..3af4880 100644 (file)
@@ -752,9 +752,13 @@ void ExprStatementNode::streamTo(SourceStream& s) const
 
 void IfNode::streamTo(SourceStream& s) const
 {
-    s << Endl << "if (" << expr << ')' << Indent << statement1 << Unindent;
-    if (statement2)
-        s << Endl << "else" << Indent << statement2 << Unindent;
+    s << Endl << "if (" << m_condition << ')' << Indent << m_ifBlock << Unindent;
+}
+
+void IfElseNode::streamTo(SourceStream& s) const
+{
+    IfNode::streamTo(s);
+    s << Endl << "else" << Indent << m_elseBlock << Unindent;
 }
 
 void DoWhileNode::streamTo(SourceStream& s) const