velocity-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cbris...@apache.org
Subject svn commit: r1753788 [1/2] - in /velocity/engine/trunk: src/changes/ velocity-engine-core/src/main/java/org/apache/velocity/context/ velocity-engine-core/src/main/java/org/apache/velocity/runtime/ velocity-engine-core/src/main/java/org/apache/velocity/...
Date Fri, 22 Jul 2016 13:23:38 GMT
Author: cbrisson
Date: Fri Jul 22 13:23:37 2016
New Revision: 1753788

URL: http://svn.apache.org/viewvc?rev=1753788&view=rev
Log:
Applied Jarkko's memory saving patch that drops Tokens while parsing.
Review and specific tests still in progress, but already functionnal.
One change from the patch: String interning straregy has been made a boolean configuration property.


Modified:
    velocity/engine/trunk/src/changes/changes.xml
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/context/AbstractContext.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAssignment.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComparisonNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirectiveAssign.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTExpression.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFalse.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIncludeStatement.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIndex.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMathNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTModNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTNotNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTrue.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTVariable.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTWord.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTprocess.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
    velocity/engine/trunk/velocity-engine-core/src/main/resources/org/apache/velocity/runtime/defaults/velocity.properties
    velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java

Modified: velocity/engine/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/changes/changes.xml?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/src/changes/changes.xml (original)
+++ velocity/engine/trunk/src/changes/changes.xml Fri Jul 22 13:23:37 2016
@@ -27,6 +27,10 @@
   <body>
     <release version="2.0" date="In Subversion">
 
+      <action type="add" dev="cbrisson" issue="VELOCITY-841" due-to="Jarkko Viinamäki">
+        applied Jarkko memory-saving patch which frees tokens while parsing
+      </action>
+      
       <action type="fix" dev="cbrisson" issue="VELOCITY-843">
         support $array.empty, as for $list.empty
       </action>

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/context/AbstractContext.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/context/AbstractContext.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/context/AbstractContext.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/context/AbstractContext.java Fri Jul 22 13:23:37 2016
@@ -54,7 +54,7 @@ public abstract class AbstractContext ex
     /**
      *  the chained Context if any
      */
-    private   Context  innerContext = null;
+    private Context innerContext = null;
 
     /**
      *  Implement to return a value from the context storage.
@@ -160,7 +160,13 @@ public abstract class AbstractContext ex
         {
             return null;
         }
-        
+
+        /*
+         * We always use string interning here:
+         * 1) speed is générally less critical when populating the context than during parsing or rendering
+         * 2) a context key is very likely to be used several times, or even a lot of times, in the template (but does it save memory if runtime.string.interning is false?)
+         * 3) last but not least: we don't have access to RuntimeServices from here, the reenginering would be painful...
+         */
         return internalPut(key.intern(), value);
     }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeConstants.java Fri Jul 22 13:23:37 2016
@@ -63,6 +63,9 @@ public interface RuntimeConstants
     /** Logging of invalid references. */
     String RUNTIME_LOG_REFERENCE_LOG_INVALID = "runtime.log.invalid.references";
 
+    /** Whether to use string interning. */
+    String RUNTIME_STRING_INTERNING = "runtime.string.interning";
+
     /*
      * ----------------------------------------------------------------------
      * D I R E C T I V E  C O N F I G U R A T I O N

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeInstance.java Fri Jul 22 13:23:37 2016
@@ -181,6 +181,11 @@ public class RuntimeInstance implements
     private Introspector introspector = null;
 
     /*
+     * Whether to use string interning
+     */
+    private boolean stringInterning = false;
+
+    /*
      * Settings for provision of root scope for evaluate(...) calls.
      */
     private String evaluateScopeName = "evaluate";
@@ -232,6 +237,7 @@ public class RuntimeInstance implements
                 log.trace("RuntimeInstance initializing.");
                 
                 initializeProperties();
+                initializeSelfProperties();
                 initializeLog();
                 initializeResourceManager();
                 initializeDirectives();
@@ -288,6 +294,7 @@ public class RuntimeInstance implements
         this.runtimeDirectives = new Hashtable();
         this.runtimeDirectivesShared = null;
         this.uberSpect = null;
+        this.stringInterning = false;
 
         /*
          *  create a VM factory, introspector, and application attributes
@@ -335,6 +342,14 @@ public class RuntimeInstance implements
     }
 
     /**
+     *  Initialize runtime internal properties
+     */
+    private void initializeSelfProperties()
+    {
+        stringInterning = getBoolean(RUNTIME_STRING_INTERNING, true);
+    }
+
+    /**
      *  Gets the classname for the Uberspect introspection package and
      *  instantiates an instance.
      */
@@ -1708,7 +1723,7 @@ public class RuntimeInstance implements
                                    List<Macro.MacroArg> macroArgs,
                                    Template definingTemplate)
     {
-        return vmFactory.addVelocimacro(name.intern(), macro, macroArgs, definingTemplate);
+        return vmFactory.addVelocimacro(stringInterning ? name.intern() : name, macro, macroArgs, definingTemplate);
     }
 
     /**
@@ -1720,7 +1735,7 @@ public class RuntimeInstance implements
      */
     public boolean isVelocimacro(String vmName, Template template)
     {
-        return vmFactory.isVelocimacro(vmName.intern(), template);
+        return vmFactory.isVelocimacro(stringInterning ? vmName.intern() : vmName, template);
     }
 
     /* --------------------------------------------------------------------
@@ -1844,4 +1859,13 @@ public class RuntimeInstance implements
         return uberSpect;
     }
 
+    /**
+     * Whether to use string interning
+     *
+     * @return boolean
+     */
+    public boolean useStringInterning()
+    {
+        return stringInterning;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/RuntimeServices.java Fri Jul 22 13:23:37 2016
@@ -474,4 +474,5 @@ public interface RuntimeServices
      */
     public Directive getDirective(String name);
 
+    public boolean useStringInterning();
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Block.java Fri Jul 22 13:23:37 2016
@@ -65,7 +65,7 @@ public abstract class Block extends Dire
     {
         super.init(rs, context, node);
 
-        log = rs.getLog();
+        log = rsvc.getLog();
 
         /**
          * No checking is done. We just grab the last child node and assume

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/BlockMacro.java Fri Jul 22 13:23:37 2016
@@ -62,11 +62,6 @@ public class BlockMacro extends Block
     private String name;
     private RuntimeMacro macro;
 
-    public BlockMacro(String name)
-    {
-        this.name = name;
-    }
-    
     public String getName()
     {
         return key;
@@ -90,20 +85,22 @@ public class BlockMacro extends Block
      * @param node
      * @throws TemplateInitException
      */
-    public void init(RuntimeServices rs, InternalContextAdapter context, Node node)
+    public void init(RuntimeServices rs, String macroName, InternalContextAdapter context, Node node)
         throws TemplateInitException
     {
+        this.name = macroName;
+
         super.init(rs, context, node);
-        
+
         // get name of the reference that refers to AST block passed to block macro call
         key = rsvc.getString(RuntimeConstants.VM_BODY_REFERENCE, "bodyContent");
 
         // use the macro max depth for bodyContent max depth as well
-        maxDepth = rs.getInt(RuntimeConstants.VM_MAX_DEPTH);
+        maxDepth = rsvc.getInt(RuntimeConstants.VM_MAX_DEPTH);
 
-        macro = new RuntimeMacro(name);
+        macro = new RuntimeMacro();
         macro.setLocation(getLine(), getColumn(), getTemplate());
-        macro.init(rs, context, node);
+        macro.init(rsvc, name, context, node);
     }
 
     /**

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Define.java Fri Jul 22 13:23:37 2016
@@ -72,13 +72,13 @@ public class Define extends Block
          * just assume it looks like this: $block_name. Should we check if it has
          * a '$' or not?
          */
-        key = node.jjtGetChild(0).getFirstToken().image.substring(1);
+        key = node.jjtGetChild(0).getFirstTokenImage().substring(1);
 
         /*
          * default max depth of two is used because intentional recursion is
          * unlikely and discouraged, so make unintentional ones end fast
          */
-        maxDepth = rs.getInt(RuntimeConstants.DEFINE_DIRECTIVE_MAXDEPTH, 2);
+        maxDepth = rsvc.getInt(RuntimeConstants.DEFINE_DIRECTIVE_MAXDEPTH, 2);
     }
 
     /**

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Foreach.java Fri Jul 22 13:23:37 2016
@@ -138,9 +138,8 @@ public class Foreach extends Directive
         {
             /*
              * the default, error-prone way which we'll remove
-             *  TODO : remove if all goes well
              */
-            elementKey = sn.getFirstToken().image.substring(1);
+        	elementKey = sn.getFirstTokenImage().substring(1);
         }
         
         /*

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Macro.java Fri Jul 22 13:23:37 2016
@@ -112,9 +112,9 @@ public class Macro extends Directive
 
         
         // Add this macro to the VelocimacroManager now that it has been initialized.        
-        List<MacroArg> macroArgs = getArgArray(node, rs);
+        List<MacroArg> macroArgs = getArgArray(node, rsvc);
         int numArgs = node.jjtGetNumChildren();
-        rs.addVelocimacro(macroArgs.get(0).name, node.jjtGetChild(numArgs - 1), 
+        rsvc.addVelocimacro(macroArgs.get(0).name, node.jjtGetChild(numArgs - 1),
             macroArgs, node.getTemplate());
     }
     
@@ -203,8 +203,8 @@ public class Macro extends Directive
             if (curnode.getType() == ParserTreeConstants.JJTDIRECTIVEASSIGN)
             {
                 // This is an argument with a default value
-              
-                macroArg.name = curnode.getFirstToken().image;
+            	macroArg.name = curnode.getFirstTokenImage();
+            	
                 // Inforced by the parser there will be an argument here.
                 i++;
                 curnode = node.jjtGetChild(i);
@@ -213,7 +213,7 @@ public class Macro extends Directive
             else
             {
                 // An argument without a default value
-                macroArg.name = curnode.getFirstToken().image;
+               	macroArg.name = curnode.getFirstTokenImage();
             }
             
             // trim off the leading $ for the args after the macro name.

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/RuntimeMacro.java Fri Jul 22 13:23:37 2016
@@ -77,22 +77,6 @@ public class RuntimeMacro extends Direct
     private String badArgsErrorMsg = null;
 
     /**
-     * Create a RuntimeMacro instance. Macro name and source
-     * template stored for later use.
-     *
-     * @param macroName name of the macro
-     */
-    public RuntimeMacro(String macroName)
-    {
-        if (macroName == null)
-        {
-            throw new IllegalArgumentException("Null arguments");
-        }
-
-        this.macroName = macroName.intern();
-    }
-
-    /**
      * Return name of this Velocimacro.
      *
      * @return The name of this Velocimacro.
@@ -126,18 +110,25 @@ public class RuntimeMacro extends Direct
 
 
     /**
-     * Intialize the Runtime macro. At the init time no implementation so we
+     * Initialize the Runtime macro. At the init time no implementation so we
      * just save the values to use at the render time.
      *
      * @param rs runtime services
      * @param context InternalContextAdapter
      * @param node node containing the macro call
      */
-    public void init(RuntimeServices rs, InternalContextAdapter context,
+    public void init(RuntimeServices rs, String name, InternalContextAdapter context,
                      Node node)
     {
         super.init(rs, context, node);
-        rsvc = rs;
+
+        macroName = name;
+        if (macroName == null)
+        {
+            throw new IllegalArgumentException("Null arguments");
+        }
+
+        this.macroName = rsvc.useStringInterning() ? macroName.intern() : macroName;
         this.node = node;
 
         /**
@@ -147,6 +138,7 @@ public class RuntimeMacro extends Direct
          * "#end" is a block style macro. We use starts with because the token
          * may end with '\n'
          */
+        // Tokens can be used here since we are in init() and Tokens have not been dropped yet
         Token t = node.getLastToken();
         if (t.image.startsWith(")") || t.image.startsWith("#end"))
         {
@@ -160,7 +152,7 @@ public class RuntimeMacro extends Direct
             Node child = node.jjtGetChild(n);
             if (child.getType() == ParserTreeConstants.JJTWORD)
             {
-                badArgsErrorMsg = "Invalid arg '" + child.getFirstToken().image
+                badArgsErrorMsg = "Invalid arg '" + child.getFirstTokenImage()
                 + "' in macro #" + macroName + " at " + StringUtils.formatFileString(child);
 
                 if (strictRef)  // If strict, throw now
@@ -172,6 +164,12 @@ public class RuntimeMacro extends Direct
                 }
             }
         }
+        // TODO: Improve this
+        // this is only needed if the macro does not exist during runtime
+        // since tokens are eliminated after this init call, we have to create a cached version of the
+        // literal which is in 99.9% cases waste. However, for regular macro calls (non Block macros)
+        // this doesn't create very long Strings so it's probably acceptable
+        getLiteral();
     }
 
     /**

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/Stop.java Fri Jul 22 13:23:37 2016
@@ -35,7 +35,7 @@ import java.util.ArrayList;
  * stopping.
  */
 public class Stop extends Directive
-{  
+{
     private static final StopCommand STOP_ALL = new StopCommand("StopCommand to exit merging");
 
     private boolean hasMessage = false;

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/directive/VelocimacroProxy.java Fri Jul 22 13:23:37 2016
@@ -137,10 +137,10 @@ public class VelocimacroProxy extends Di
      */
     public void init(RuntimeServices rs)
     {
-        rsvc = rs;
+        rsvc = rs; // CB TODO - why not super.init(rs) ?
       
         // this is a very expensive call (ExtendedProperties is very slow)
-        strictArguments = rs.getConfiguration().getBoolean(
+        strictArguments = rsvc.getConfiguration().getBoolean(
             RuntimeConstants.VM_ARGUMENTS_STRICT, false);
 
         // get the macro call depth limit
@@ -155,7 +155,7 @@ public class VelocimacroProxy extends Di
     {
         return render(context, writer, node, null);
     }
-    
+
     /**
      * Renders the macro using the context.
      * 
@@ -186,7 +186,7 @@ public class VelocimacroProxy extends Di
         checkDepth(context);
 
         // put macro arg values and save the returned old/new value pairs
-        Object[][] values = handleArgValues(context, node, callArgNum);
+        Object[] values = handleArgValues(context, node, callArgNum);
         try
         {
             // render the velocity macro
@@ -226,9 +226,9 @@ public class VelocimacroProxy extends Di
             {
                 MacroArg macroArg = macroArgs.get(i);
                 current = context.get(macroArg.name);
-                if (current == values[i-1][1])
+                if (current == values[(i-1) * 2 + 1])
                 {
-                    Object old = values[i-1][0];
+                    Object old = values[(i-1) * 2];
                     if (old != null)
                     {
                         context.put(macroArg.name, old);
@@ -241,7 +241,7 @@ public class VelocimacroProxy extends Di
             }
         }
     }
-
+    
     /**
      * Check whether the number of arguments given matches the number defined.
      */
@@ -305,16 +305,17 @@ public class VelocimacroProxy extends Di
      * the argument names.  Store and return an array of old and new values
      * paired for each argument name, for later cleanup.
      */
-    protected Object[][] handleArgValues(InternalContextAdapter context,
+    protected Object[] handleArgValues(InternalContextAdapter context,
                                          Node node, int callArgNum)
     {
-        Object[][] values = new Object[macroArgs.size()][2];
+    	// Changed two dimensional array to single dimensional to optimize memory lookups
+        Object[] values = new Object[macroArgs.size() * 2];
           
         // Move arguments into the macro's context. Start at one to skip macro name
         for (int i = 1; i < macroArgs.size(); i++)
         {
             MacroArg macroArg = macroArgs.get(i);
-            values[i-1][0] = context.get(macroArg.name);
+            values[(i-1) * 2] = context.get(macroArg.name);
 
             // put the new value in
             Object newVal = null;
@@ -355,12 +356,12 @@ public class VelocimacroProxy extends Di
             }
 
             context.put(macroArg.name, newVal);
-            values[i-1][1] = newVal;
+            values[(i-1) * 2 + 1] = newVal;
         }
 
         // return the array of replaced and new values
         return values;
     }
-
+    
 }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAndNode.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -109,5 +110,17 @@ public class ASTAndNode extends SimpleNo
 
         return false;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAssignment.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAssignment.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAssignment.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTAssignment.java Fri Jul 22 13:23:37 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.runtime.pars
  * under the License.    
  */
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -50,4 +52,16 @@ public class ASTAssignment extends Simpl
     {
         return visitor.visit(this, data);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTBlock.java Fri Jul 22 13:23:37 2016
@@ -23,6 +23,7 @@ import org.apache.velocity.context.Inter
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 import java.io.IOException;
@@ -73,4 +74,16 @@ public class ASTBlock extends SimpleNode
 
         return true;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComment.java Fri Jul 22 13:23:37 2016
@@ -23,6 +23,7 @@ import org.apache.velocity.context.Inter
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.runtime.parser.Token;
 
@@ -87,6 +88,8 @@ public class ASTComment extends SimpleNo
         {
             carr = t.image.substring(0, (loc1 == -1) ? loc2 : loc1).toCharArray();
         }
+        
+        cleanupParserAndTokens();
 
         return data;
     }
@@ -100,5 +103,5 @@ public class ASTComment extends SimpleNo
         writer.write(carr);
         return true;
     }
-
+    
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComparisonNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComparisonNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComparisonNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTComparisonNode.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.exception.VelocityException;
 import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.parser.Parser;
@@ -150,5 +151,17 @@ public abstract class ASTComparisonNode
     {
         return Boolean.valueOf(evaluate(context));
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirective.java Fri Jul 22 13:23:37 2016
@@ -122,7 +122,7 @@ public class ASTDirective extends Simple
                 }
 
                 directive.setLocation(getLine(), getColumn(), getTemplate());
-                directive.init(rsvc, context,this);
+                directive.init(rsvc, context, this);
             }
             else if( directiveName.startsWith("@") )
             {
@@ -131,12 +131,12 @@ public class ASTDirective extends Simple
                     // block macro call (normal macro call but has AST body)
                     directiveName = directiveName.substring(1);
 
-                    directive = new BlockMacro(directiveName);
+                    directive = new BlockMacro();
                     directive.setLocation(getLine(), getColumn(), getTemplate());
 
                     try
                     {
-                        directive.init( rsvc, context, this );
+                        ((BlockMacro)directive).init( rsvc, directiveName, context, this );
                     }
                     catch (TemplateInitException die)
                     {
@@ -160,7 +160,7 @@ public class ASTDirective extends Simple
                 /**
                  * Create a new RuntimeMacro
                  */
-                directive = new RuntimeMacro(directiveName);
+                directive = new RuntimeMacro();
                 directive.setLocation(getLine(), getColumn(), getTemplate());
 
                 /**
@@ -168,7 +168,7 @@ public class ASTDirective extends Simple
                  */
                 try
                 {
-                    directive.init( rsvc, context, this );
+                    ((RuntimeMacro)directive).init( rsvc, directiveName, context, this );
                 }
 
                 /**
@@ -183,11 +183,15 @@ public class ASTDirective extends Simple
                             die.getLineNumber() + getLine());
                 }
                 isDirective = true;
+                
             }
 
             isInitialized = true;
+            
+            saveTokenImages();
+            cleanupParserAndTokens();
         }
-
+        
         return data;
     }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirectiveAssign.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirectiveAssign.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirectiveAssign.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTDirectiveAssign.java Fri Jul 22 13:23:37 2016
@@ -18,6 +18,8 @@
  */
 package org.apache.velocity.runtime.parser.node;
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 public class ASTDirectiveAssign extends SimpleNode
@@ -32,5 +34,18 @@ public class ASTDirectiveAssign extends
   {
     super(p, i);
   }
+  
+  /**
+   * @throws TemplateInitException
+   * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+   */
+  public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+  {
+  	Object obj = super.init(context, data);
+  	saveTokenImages();
+  	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+  	return obj;
+  }
+  
 
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseIfStatement.java Fri Jul 22 13:23:37 2016
@@ -23,6 +23,7 @@ import org.apache.velocity.context.Inter
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 import java.io.IOException;
@@ -91,4 +92,16 @@ public class ASTElseIfStatement extends
     {
         return jjtGetChild(1).render( context, writer );
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTElseStatement.java Fri Jul 22 13:23:37 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.runtime.pars
  */
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -69,5 +70,16 @@ public class ASTElseStatement extends Si
     {
         return true;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTEscapedDirective.java Fri Jul 22 13:23:37 2016
@@ -25,6 +25,10 @@ import org.apache.velocity.runtime.parse
 import java.io.IOException;
 import java.io.Writer;
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
+import org.apache.velocity.runtime.parser.Parser;
+
 /**
  * This class is responsible for handling EscapedDirectives
  *  in VTL.
@@ -69,8 +73,19 @@ public class ASTEscapedDirective extends
     public boolean render(InternalContextAdapter context, Writer writer)
         throws IOException
     {
-        writer.write(getFirstToken().image);
+    	writer.write(firstImage);
         return true;
     }
-
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	saveTokenImages();
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTExpression.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTExpression.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTExpression.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTExpression.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -70,4 +71,16 @@ public class ASTExpression extends Simpl
     {
         return jjtGetChild(0).value(context);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	saveTokenImages();
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFalse.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFalse.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFalse.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFalse.java Fri Jul 22 13:23:37 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.runtime.pars
  */
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -69,4 +70,15 @@ public class ASTFalse extends SimpleNode
     {
         return value;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTFloatingPointLiteral.java Fri Jul 22 13:23:37 2016
@@ -97,6 +97,7 @@ public class ASTFloatingPointLiteral ext
             value = new BigDecimal( str );
 
         }
+        cleanupParserAndTokens();
 
         return data;
     }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIdentifier.java Fri Jul 22 13:23:37 2016
@@ -101,12 +101,15 @@ public class ASTIdentifier extends Simpl
     {
         super.init(context, data);
 
-        identifier = getFirstToken().image.intern();
+        identifier = rsvc.useStringInterning() ? getFirstToken().image.intern() : getFirstToken().image;
 
         uberInfo = new Info(getTemplateName(), getLine(), getColumn());
 
         strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
         
+        saveTokenImages();
+        cleanupParserAndTokens();
+        
         return data;
     }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIfStatement.java Fri Jul 22 13:23:37 2016
@@ -33,6 +33,7 @@ import org.apache.velocity.context.Inter
 import org.apache.velocity.exception.MethodInvocationException;
 import org.apache.velocity.exception.ParseErrorException;
 import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 import java.io.IOException;
@@ -123,10 +124,15 @@ public class ASTIfStatement extends Simp
     public void process( InternalContextAdapter context, ParserVisitor visitor)
     {
     }
-}
-
-
-
-
-
-
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+}
\ No newline at end of file

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIncludeStatement.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIncludeStatement.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIncludeStatement.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIncludeStatement.java Fri Jul 22 13:23:37 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.runtime.pars
  * under the License.    
  */
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -51,4 +53,16 @@ public class ASTIncludeStatement extends
     {
         return visitor.visit(this, data);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIndex.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIndex.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIndex.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIndex.java Fri Jul 22 13:23:37 2016
@@ -76,6 +76,7 @@ public class ASTIndex extends SimpleNode
     {
         super.init(context, data);    
         strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
+        cleanupParserAndTokens();
         return data;
     }  
 
@@ -133,7 +134,7 @@ public class ASTIndex extends SimpleNode
                   + "' when Integer was expected at " + StringUtils.formatFileString(node));
           }
           
-          argument = new Integer(sizeint + ((Integer)argument).intValue());
+          argument = Integer.valueOf(sizeint + ((Integer)argument).intValue());
       }
       
       // Nothing to do, return the original argument

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerLiteral.java Fri Jul 22 13:23:37 2016
@@ -54,7 +54,6 @@ public class ASTIntegerLiteral extends S
         super(p, id);
     }
 
-
     /**
      * @see org.apache.velocity.runtime.parser.node.SimpleNode#jjtAccept(org.apache.velocity.runtime.parser.node.ParserVisitor, java.lang.Object)
      */
@@ -81,23 +80,21 @@ public class ASTIntegerLiteral extends S
          String str = getFirstToken().image;
          try
          {
-             value = new Integer( str );
+        	 value = Integer.valueOf( str );
          }
          catch ( NumberFormatException E1 )
          {
             try
             {
-
                 value = new Long( str );
-
             }
             catch ( NumberFormatException E2 )
             {
-
                 // if there's still an Exception it will propogate out
                 value = new BigInteger( str );
             }
         }
+        cleanupParserAndTokens();
 
         return data;
     }
@@ -109,5 +106,4 @@ public class ASTIntegerLiteral extends S
     {
         return value;
     }
-
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 import org.apache.velocity.util.StringUtils;
 
@@ -136,10 +137,22 @@ public class ASTIntegerRange extends Sim
 
         for (int i = 0; i < nbrElements; i++)
         {
-            elements.add(new Integer(value));
+            elements.add(Integer.valueOf(value));
             value += delta;
         }
 
         return elements;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMap.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 import java.util.LinkedHashMap;
@@ -84,4 +85,16 @@ public class ASTMap extends SimpleNode
 
         return objectMap;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMathNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMathNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMathNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMathNode.java Fri Jul 22 13:23:37 2016
@@ -61,6 +61,7 @@ public abstract class ASTMathNode extend
     {
         super.init(context, data);
         strictMode = rsvc.getBoolean(RuntimeConstants.STRICT_MATH, false);
+        cleanupParserAndTokens();
         return data;
     }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMethod.java Fri Jul 22 13:23:37 2016
@@ -121,6 +121,8 @@ public class ASTMethod extends SimpleNod
 
         strictRef = rsvc.getBoolean(RuntimeConstants.RUNTIME_REFERENCES_STRICT, false);
 
+        cleanupParserAndTokens();
+        
         return data;
     }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTModNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTModNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTModNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTModNode.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MathException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -75,5 +76,17 @@ public class ASTModNode extends ASTMathN
         }
         return MathUtils.modulo(left, right);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTMulNode.java Fri Jul 22 13:23:37 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.runtime.pars
  */
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -57,6 +58,18 @@ public class ASTMulNode extends ASTMathN
     {
         return MathUtils.multiply(left, right);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 }
 
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTNotNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTNotNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTNotNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTNotNode.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -74,4 +75,15 @@ public class ASTNotNode extends SimpleNo
     {
         return (jjtGetChild(0).evaluate( context ) ? Boolean.FALSE : Boolean.TRUE) ;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 import java.util.ArrayList;
@@ -75,4 +76,16 @@ public class ASTObjectArray extends Simp
 
         return objectArray;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+    
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTOrNode.java Fri Jul 22 13:23:37 2016
@@ -21,6 +21,7 @@ package org.apache.velocity.runtime.pars
 
 import org.apache.velocity.context.InternalContextAdapter;
 import org.apache.velocity.exception.MethodInvocationException;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -105,6 +106,18 @@ public class ASTOrNode extends SimpleNod
 
         return false;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }
 
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTReference.java Fri Jul 22 13:23:37 2016
@@ -137,7 +137,7 @@ public class ASTReference extends Simple
          *  so it's thread- and context-safe
          */
 
-        rootString = getRoot().intern();
+        rootString = rsvc.useStringInterning() ? getRoot().intern() : getRoot();
 
         numChildren = jjtGetNumChildren();
         
@@ -154,8 +154,9 @@ public class ASTReference extends Simple
             if (lastNode instanceof ASTIndex)
                 astIndex = (ASTIndex)lastNode;
             else
-                identifier = lastNode.getFirstToken().image;            
+            	identifier = lastNode.getFirstTokenImage();
         }
+        
 
         /*
          * make an uberinfo - saves new's later on
@@ -196,6 +197,8 @@ public class ASTReference extends Simple
                 }
             }
         }
+        saveTokenImages();
+        cleanupParserAndTokens();
                 
         return data;
     }
@@ -276,7 +279,7 @@ public class ASTReference extends Simple
                      * At this point we know that an attempt is about to be made
                      * to call a method or property on a null value.
                      */
-                    String name = jjtGetChild(i).getFirstToken().image;
+                    String name = jjtGetChild(i).getFirstTokenImage();
                     throw new VelocityException("Attempted to access '"  
                         + name + "' on a null value at "
                         + StringUtils.formatFileString(uberInfo.getTemplateName(),
@@ -328,7 +331,7 @@ public class ASTReference extends Simple
                         }
                         else
                         {
-                            name.append(".").append(node.getFirstToken().image);
+                            name.append(".").append(node.getFirstTokenImage());
                         }
                     }
                     
@@ -340,7 +343,7 @@ public class ASTReference extends Simple
                     }
                     else
                     {
-                        String property = jjtGetChild(failedChild).getFirstToken().image;
+                        String property = jjtGetChild(failedChild).getFirstTokenImage();
                         result = EventHandlerUtil.invalidGetMethod(rsvc, context, 
                                 name.toString(), previousResult, property, uberInfo);                        
                     }
@@ -639,7 +642,7 @@ public class ASTReference extends Simple
             {
                 if (strictRef)
                 {
-                    String name = jjtGetChild(i+1).getFirstToken().image;
+                    String name = jjtGetChild(i+1).getFirstTokenImage();
                     throw new MethodInvocationException("Attempted to access '"  
                         + name + "' on a null value", null, name, uberInfo.getTemplateName(),
                         jjtGetChild(i+1).getLine(), jjtGetChild(i+1).getColumn());
@@ -805,7 +808,7 @@ public class ASTReference extends Simple
                 // pattern a non-reference, and we print it out as schmoo...
                 nullString = literal();
                 escaped = true;
-                return literal();
+                return nullString;
             }
           
             /*

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTSetDirective.java Fri Jul 22 13:23:37 2016
@@ -110,9 +110,11 @@ public class ASTSetDirective extends Sim
             /*
              *  grab this now.  No need to redo each time
              */
-            leftReference = left.getFirstToken().image.substring(1);
+            leftReference = left.firstImage.substring(1);
         
             isInitialized = true;
+            
+            cleanupParserAndTokens();
         }
             
         return data;
@@ -140,7 +142,7 @@ public class ASTSetDirective extends Sim
             String rightReference = null;
             if (right instanceof ASTExpression)
             {
-                rightReference = ((ASTExpression) right).getLastToken().image;
+                rightReference = ((ASTExpression) right).lastImage;
             }
             EventHandlerUtil.invalidSetMethod(rsvc, context, leftReference, rightReference, uberInfo);
         }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTStringLiteral.java Fri Jul 22 13:23:37 2016
@@ -48,7 +48,7 @@ public class ASTStringLiteral extends Si
     private String image = "";
 
     /** true if the string contains a line comment (##) */
-    private boolean containsLineComment;
+    private boolean containsLineComment = false;
 
     /**
      * @param id
@@ -124,9 +124,9 @@ public class ASTStringLiteral extends Si
             /*
              * if appropriate, tack a space on the end (dreaded <MORE> kludge)
              */
-		 
+
 		    String interpolateimage;
-			
+
 	        /**
              * Note - this should really use a regexp to look for [^\]## but
              * apparently escaping of line comments isn't working right now anyway.
@@ -193,9 +193,16 @@ public class ASTStringLiteral extends Si
             nodeTree.init(context, rsvc);
         }
 
+        cleanupParserAndTokens();
+
         return data;
     }
 
+    public String literal()
+    {
+    	return image;
+    }
+
     /**
      * Adjust all the line and column numbers that comprise a node so that they
      * are corrected for the string literals position within the template file.

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTText.java Fri Jul 22 13:23:37 2016
@@ -70,6 +70,8 @@ public class ASTText extends SimpleNode
         String text = NodeUtils.tokenLiteral( t );
 
         ctext = text.toCharArray();
+        
+        cleanupParserAndTokens();
 
         return data;
     }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTextblock.java Fri Jul 22 13:23:37 2016
@@ -74,11 +74,14 @@ public class ASTTextblock extends Simple
         
         String text = t.image;
         
-        // t.image is in format: #% <string> %#
+        // t.image is in format: #[[ <string> ]]#
         // we must strip away the hash tags
         text = text.substring(START.length(), text.length() - END.length());
 
         ctext = text.toCharArray();
+        
+        cleanupParserAndTokens();
+        
         return data;
     }
 

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTrue.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTrue.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTrue.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTTrue.java Fri Jul 22 13:23:37 2016
@@ -20,6 +20,7 @@ package org.apache.velocity.runtime.pars
  */
 
 import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -69,4 +70,16 @@ public class ASTTrue extends SimpleNode
     {
         return value;
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTVariable.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTVariable.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTVariable.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTVariable.java Fri Jul 22 13:23:37 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.runtime.pars
  * under the License.    
  */
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 
@@ -51,4 +53,16 @@ public class ASTVariable extends SimpleN
     {
         return visitor.visit(this, data);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
+
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTWord.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTWord.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTWord.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTWord.java Fri Jul 22 13:23:37 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.runtime.pars
  * under the License.    
  */
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -50,4 +52,16 @@ public class ASTWord extends SimpleNode
     {
         return visitor.visit(this, data);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	saveTokenImages();
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTprocess.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTprocess.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTprocess.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/ASTprocess.java Fri Jul 22 13:23:37 2016
@@ -19,6 +19,8 @@ package org.apache.velocity.runtime.pars
  * under the License.    
  */
 
+import org.apache.velocity.context.InternalContextAdapter;
+import org.apache.velocity.exception.TemplateInitException;
 import org.apache.velocity.runtime.parser.Parser;
 
 /**
@@ -50,4 +52,15 @@ public class ASTprocess extends SimpleNo
     {
         return visitor.visit(this, data);
     }
+    
+    /**
+     * @throws TemplateInitException
+     * @see org.apache.velocity.runtime.parser.node.Node#init(org.apache.velocity.context.InternalContextAdapter, java.lang.Object)
+     */
+    public Object init( InternalContextAdapter context, Object data) throws TemplateInitException
+    {
+    	Object obj = super.init(context, data);
+    	cleanupParserAndTokens(); // drop reference to Parser and all JavaCC Tokens
+    	return obj;
+    }
 }

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/Node.java Fri Jul 22 13:23:37 2016
@@ -201,15 +201,24 @@ public interface Node extends Renderable
      * @return The current column position.
      */
     public int getColumn();
-    
+
     /**
      * @return the file name of the template
      */
     public String getTemplateName();
 
     /**
+     * @return cached image (String) of the first Token for this Node returned by the Parser
+     */
+    public String getFirstTokenImage();
+
+    /**
+     * @return cached image (String) of the last Token for this Node returned by the Parser
+     */
+    public String getLastTokenImage();
+
+    /**
      * @return the template this node belongs to
      */
     public Template getTemplate();
-
 }



Mime
View raw message