You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2016/07/22 13:23:38 UTC

svn commit: r1753788 [2/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/...

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/parser/node/SimpleNode.java Fri Jul 22 13:23:37 2016
@@ -56,11 +56,10 @@ public class SimpleNode implements Node
     protected int id;
 
     /** */
-    // TODO - It seems that this field is only valid when parsing, and should not be kept around.
     protected Parser parser;
 
     /** */
-    protected int info; // added
+    protected int info;
 
     /** */
     public boolean state;
@@ -76,6 +75,32 @@ public class SimpleNode implements Node
 
     protected Template template;
 
+    /**
+     * For caching the literal value.
+     */
+    protected String literal = null;
+
+    /**
+     * Line number for this Node in the vm source file.
+     */
+
+    protected int line;
+
+    /**
+     * Column number for this Node in the vm source file.
+     */
+    protected int column;
+
+    /**
+     * String image variable of the first Token element that was parsed and connected to this Node.
+     */
+    protected String firstImage;
+
+    /**
+     * String image variable of the last Token element that was parsed and connected to this Node.
+     */
+    protected String lastImage;
+
     public RuntimeServices getRuntimeServices()
     {
       return rsvc;
@@ -272,11 +297,17 @@ public class SimpleNode implements Node
      */
     public String literal()
     {
+        if( literal != null )
+        {
+            return literal;
+        }
+
         // if we have only one string, just return it and avoid
         // buffer allocation. VELOCITY-606
         if (first == last)
         {
-            return NodeUtils.tokenLiteral(first);
+            literal = NodeUtils.tokenLiteral(first);
+            return literal;
         }
 
         Token t = first;
@@ -286,7 +317,8 @@ public class SimpleNode implements Node
             t = t.next;
             sb.append(NodeUtils.tokenLiteral(t));
         }
-        return sb.toString();
+        literal = sb.toString();
+        return literal;
     }
 
     /**
@@ -309,6 +341,9 @@ public class SimpleNode implements Node
             jjtGetChild(i).init( context, data);
         }
 
+        line = first.beginLine;
+        column = first.beginColumn;
+
         return data;
     }
 
@@ -398,7 +433,7 @@ public class SimpleNode implements Node
      */
     public int getLine()
     {
-        return first.beginLine;
+        return line;
     }
 
     /**
@@ -406,7 +441,7 @@ public class SimpleNode implements Node
      */
     public int getColumn()
     {
-        return first.beginColumn;
+        return column;
     }
 
     /**
@@ -435,15 +470,58 @@ public class SimpleNode implements Node
         String tok = tokens.toString();
         if (tok.length() > 50) tok = tok.substring(0, 50) + "...";
         return getClass().getSimpleName() + " [id=" + id + ", info=" + info + ", invalid="
-		        + invalid
-		        + ", tokens=" + tok + "]";
+                + invalid
+                + ", tokens=" + tok + "]";
     }
 
-	public String getTemplateName()
+    public String getTemplateName()
     {
       return template.getName();
     }
 
+    /**
+     * Call before calling cleanupParserAndTokens() if you want to store image of
+     * the first and last token of this node.
+     */
+    public void saveTokenImages()
+    {
+        if( first != null )
+        {
+            this.firstImage = first.image;
+        }
+        if( last != null )
+        {
+            this.lastImage = last.image;
+        }
+    }
+
+    /**
+     * Removes references to Parser and Tokens since they are not needed anymore at this point.
+     *
+     * This allows us to save memory quite a bit.
+     */
+    public void cleanupParserAndTokens()
+    {
+        this.parser = null;
+        this.first = null;
+        this.last = null;
+    }
+
+    /**
+     * @return String image variable of the first Token element that was parsed and connected to this Node.
+     */
+    public String getFirstTokenImage()
+    {
+        return firstImage;
+    }
+
+    /**
+     * @return String image variable of the last Token element that was parsed and connected to this Node.
+     */
+    public String getLastTokenImage()
+    {
+        return lastImage;
+    }
+
     public Template getTemplate() { return template; }
 }
-

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/visitor/NodeViewMode.java Fri Jul 22 13:23:37 2016
@@ -63,6 +63,7 @@ public class NodeViewMode extends BaseVi
 
         if (showTokens)
         {
+        	// TODO: Token reference
             t = node.getFirstToken();
 
             if (t.specialToken != null && ! t.specialToken.image.startsWith("##"))

Modified: velocity/engine/trunk/velocity-engine-core/src/main/resources/org/apache/velocity/runtime/defaults/velocity.properties
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/resources/org/apache/velocity/runtime/defaults/velocity.properties?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/resources/org/apache/velocity/runtime/defaults/velocity.properties (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/resources/org/apache/velocity/runtime/defaults/velocity.properties Fri Jul 22 13:23:37 2016
@@ -29,6 +29,13 @@ input.encoding=ISO-8859-1
 output.encoding=ISO-8859-1
 
 # ----------------------------------------------------------------------------
+# Strings interning
+# ----------------------------------------------------------------------------
+# Set to true to optimize memory, to false to optimize speed
+
+runtime.string.interning = true
+
+# ----------------------------------------------------------------------------
 # F O R E A C H  P R O P E R T I E S
 # ----------------------------------------------------------------------------
 # This property controls how many loops #foreach can execute. The default

Modified: velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java?rev=1753788&r1=1753787&r2=1753788&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/test/java/org/apache/velocity/test/misc/ExceptionGeneratingDirective.java Fri Jul 22 13:23:37 2016
@@ -38,7 +38,6 @@ import java.io.Writer;
  */
 public class ExceptionGeneratingDirective extends Directive
 {
-
     public String getName()
     {
         return "Exception";