From 88ad54171ff0f9738d7bfc6b7b66e35aea435967 Mon Sep 17 00:00:00 2001 From: "igor%mir2.org" Date: Thu, 5 Dec 2002 21:04:30 +0000 Subject: [PATCH] Remove generation of closure icode for function statements as they are initialized at script/function start, not at point of declaration. This redundant closure icodes were effectively no-operation but caused bigger stack to be allocated then necessary. --- .../org/mozilla/javascript/Interpreter.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/js/rhino/src/org/mozilla/javascript/Interpreter.java b/js/rhino/src/org/mozilla/javascript/Interpreter.java index 00e15330506..af82ab8c04a 100644 --- a/js/rhino/src/org/mozilla/javascript/Interpreter.java +++ b/js/rhino/src/org/mozilla/javascript/Interpreter.java @@ -271,13 +271,20 @@ public class Interpreter { switch (type) { case TokenStream.FUNCTION : { - Node fn = (Node) node.getProp(Node.FUNCTION_PROP); - int index = fn.getExistingIntProp(Node.FUNCTION_PROP); - iCodeTop = addByte(TokenStream.CLOSURE, iCodeTop); - iCodeTop = addIndex(index, iCodeTop); - itsStackDepth++; - if (itsStackDepth > itsData.itsMaxStack) - itsData.itsMaxStack = itsStackDepth; + FunctionNode fn + = (FunctionNode) node.getProp(Node.FUNCTION_PROP); + if (fn.itsFunctionType != FunctionNode.FUNCTION_STATEMENT) { + // Only function expressions or function expression + // statements needs closure code creating new function + // object on stack as function statements are initialized + // at script/function start + int index = fn.getExistingIntProp(Node.FUNCTION_PROP); + iCodeTop = addByte(TokenStream.CLOSURE, iCodeTop); + iCodeTop = addIndex(index, iCodeTop); + itsStackDepth++; + if (itsStackDepth > itsData.itsMaxStack) + itsData.itsMaxStack = itsStackDepth; + } break; }