Reviewed by Maciej Stachowiak.
authorggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Oct 2007 07:11:53 +0000 (07:11 +0000)
committerggaren <ggaren@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 20 Oct 2007 07:11:53 +0000 (07:11 +0000)
        Fixed http://bugs.webkit.org/show_bug.cgi?id=15570
        Store gathered declaration nodes in the function body node.

        This means that you only have to gather the declaration nodes the first
        time the function executes. Performance gain of 2.10% on SunSpider,
        0.90% on command-line JS iBench.

        * kjs/nodes.cpp: Split declaration stack initialization code off into
        initializeDeclarationStacks().
        (FunctionBodyNode::FunctionBodyNode):
        (FunctionBodyNode::initializeDeclarationStacks):
        (FunctionBodyNode::processDeclarations):

        * kjs/nodes.h: Changed DeclarationStacks structure to hold references,
        since the actual Vectors are now stored either on the stack or in the
        function body node.

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

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h

index 2934fd5..62960bb 100644 (file)
@@ -1,3 +1,24 @@
+2007-10-20  Geoffrey Garen  <ggaren@apple.com>
+
+        Reviewed by Maciej Stachowiak.
+
+        Fixed http://bugs.webkit.org/show_bug.cgi?id=15570
+        Store gathered declaration nodes in the function body node.
+        
+        This means that you only have to gather the declaration nodes the first 
+        time the function executes. Performance gain of 2.10% on SunSpider, 
+        0.90% on command-line JS iBench.
+
+        * kjs/nodes.cpp: Split declaration stack initialization code off into 
+        initializeDeclarationStacks().
+        (FunctionBodyNode::FunctionBodyNode):
+        (FunctionBodyNode::initializeDeclarationStacks):
+        (FunctionBodyNode::processDeclarations):
+
+        * kjs/nodes.h: Changed DeclarationStacks structure to hold references, 
+        since the actual Vectors are now stored either on the stack or in the 
+        function body node.
+
 2007-10-19  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Darin Adler.
index 48fc33a..682f704 100644 (file)
@@ -2422,19 +2422,19 @@ FunctionBodyNode::FunctionBodyNode(SourceElementsNode *s)
     : BlockNode(s)
     , m_sourceURL(Lexer::curr()->sourceURL())
     , m_sourceId(Parser::sid)
+    , m_initializedDeclarationStacks(false)
 {
-
   setLoc(-1, -1);
 }
 
-void FunctionBodyNode::processDeclarations(ExecState* exec)
+void FunctionBodyNode::initializeDeclarationStacks()
 {
     Node* node = source.get();
     if (!node)
         return;
 
-    DeclarationStacks stacks;
-    DeclarationStacks::NodeStack& nodeStack = stacks.nodeStack;
+    DeclarationStacks::NodeStack nodeStack;
+    DeclarationStacks stacks(nodeStack, m_varStack, m_functionStack);
     
     while (true) {
         ASSERT(node->mayHaveDeclarations()); // Otherwise, we wasted time putting an irrelevant node on the stack.
@@ -2447,16 +2447,22 @@ void FunctionBodyNode::processDeclarations(ExecState* exec)
         node = nodeStack[size];
         nodeStack.shrink(size);
     }
-    
+
+    m_initializedDeclarationStacks = true;
+}
+
+void FunctionBodyNode::processDeclarations(ExecState* exec)
+{
+    if (!m_initializedDeclarationStacks)
+        initializeDeclarationStacks();
+
     size_t i, size;
 
-    DeclarationStacks::FunctionStack& functionStack = stacks.functionStack;
-    for (i = 0, size = functionStack.size(); i < size; ++i)
-        functionStack[i]->processDeclaration(exec);
+    for (i = 0, size = m_functionStack.size(); i < size; ++i)
+        m_functionStack[i]->processDeclaration(exec);
 
-    DeclarationStacks::VarStack& varStack = stacks.varStack;
-    for (i = 0, size = varStack.size(); i < size; ++i)
-        varStack[i]->processDeclaration(exec);
+    for (i = 0, size = m_varStack.size(); i < size; ++i)
+        m_varStack[i]->processDeclaration(exec);
 }
 
 void FunctionBodyNode::addParam(const Identifier& ident)
index 9c01dc4..f36fd9e 100644 (file)
@@ -89,9 +89,16 @@ namespace KJS {
       typedef Vector<VarDeclNode*, 16> VarStack;
       typedef Vector<FuncDeclNode*, 16> FunctionStack;
       
-      NodeStack nodeStack;
-      VarStack varStack; 
-      FunctionStack functionStack;
+      DeclarationStacks(NodeStack& n, VarStack& v, FunctionStack& f)
+        : nodeStack(n)
+        , varStack(v)
+        , functionStack(f)
+      {
+      }
+        
+      NodeStack& nodeStack;
+      VarStack& varStack; 
+      FunctionStack& functionStack;
   };
 
   class Node {
@@ -1056,6 +1063,11 @@ namespace KJS {
     UString m_sourceURL;
     int m_sourceId;
     Vector<Identifier> m_parameters;
+
+    void initializeDeclarationStacks();
+    bool m_initializedDeclarationStacks;
+    DeclarationStacks::VarStack m_varStack;
+    DeclarationStacks::FunctionStack m_functionStack;
   };
 
   class FuncExprNode : public Node {