You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by dl...@apache.org on 2006/11/08 23:58:10 UTC
svn commit: r472679 -
/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
Author: dlr
Date: Wed Nov 8 14:58:09 2006
New Revision: 472679
URL: http://svn.apache.org/viewvc?view=rev&rev=472679
Log:
Minor performance optimization and refactoring for clarity.
* src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
Consolidate header JavaDoc, and remove $Version: $ tag.
(value): Pre-allocate the initial storage for the ArrayList we
return. Improve some variable names and inline comments, and tweak
some formatting.
Modified:
jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
Modified: jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java
URL: http://svn.apache.org/viewvc/jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java?view=diff&rev=472679&r1=472678&r2=472679
==============================================================================
--- jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java (original)
+++ jakarta/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTIntegerRange.java Wed Nov 8 14:58:09 2006
@@ -19,16 +19,6 @@
* under the License.
*/
-/**
- * handles the range 'operator' [ n .. m ]
- *
- * Please look at the Parser.jjt file which is
- * what controls the generation of this class.
- *
- * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
- * @version $Id$
-*/
-
import java.util.ArrayList;
import java.util.List;
@@ -38,11 +28,15 @@
import org.apache.velocity.runtime.parser.ParserVisitor;
/**
+ * handles the range 'operator' [ n .. m ]
+ *
+ * Please look at the Parser.jjt file which is
+ * what controls the generation of this class.
*
+ * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
*/
public class ASTIntegerRange extends SimpleNode
{
-
/**
* @param id
*/
@@ -60,7 +54,6 @@
super(p, id);
}
-
/**
* @see org.apache.velocity.runtime.parser.node.SimpleNode#jjtAccept(org.apache.velocity.runtime.parser.ParserVisitor, java.lang.Object)
*/
@@ -128,30 +121,29 @@
* find out how many there are
*/
- int num = Math.abs( l - r );
- num += 1;
+ int nbrElements = Math.abs( l - r );
+ nbrElements += 1;
/*
- * see if your increment is Pos or Neg
+ * Determine whether the increment is positive or negative.
*/
int delta = ( l >= r ) ? -1 : 1;
/*
- * make the vector and fill it
+ * Fill the range with the appropriate values.
*/
- List elements = new ArrayList();
- int val = l;
+ List elements = new ArrayList(nbrElements);
+ int value = l;
- for(int i =0; i < num; i++)
+ for (int i = 0; i < nbrElements; i++)
{
// TODO: JDK 1.4+ -> valueOf()
- elements.add(new Integer(val));
- val += delta;
+ elements.add(new Integer(value));
+ value += delta;
}
return elements;
}
}
-
---------------------------------------------------------------------
To unsubscribe, e-mail: velocity-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-dev-help@jakarta.apache.org