You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by nb...@apache.org on 2008/08/13 02:03:22 UTC
svn commit: r685387 - in /velocity/engine/trunk/src:
java/org/apache/velocity/runtime/parser/Parser.java
java/org/apache/velocity/runtime/parser/Parser.jj
java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
parser/Parser.jjt
Author: nbubna
Date: Tue Aug 12 17:03:19 2008
New Revision: 685387
URL: http://svn.apache.org/viewvc?rev=685387&view=rev
Log:
misc performance tweaks (thx to Jarkko Viinamaki in patch for VELOCITY-607)
Modified:
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
velocity/engine/trunk/src/parser/Parser.jjt
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java?rev=685387&r1=685386&r2=685387&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.java Tue Aug 12 17:03:19 2008
@@ -171,15 +171,18 @@
boolean bRecognizedDirective = false;
+ // we don't have to call substring method all the time in this method
+ String dirTag = strDirective.substring(1);
+
/*
* is this a PD or a control directive?
*/
- if ( isDirective( strDirective.substring(1)))
+ if ( isDirective(dirTag) )
{
bRecognizedDirective = true;
}
- else if ( rsvc.isVelocimacro( strDirective.substring(1), currentTemplateName))
+ else if ( rsvc.isVelocimacro(dirTag, currentTemplateName))
{
bRecognizedDirective = true;
}
@@ -187,12 +190,12 @@
{
/* order for speed? */
- if ( strDirective.substring(1).equals("if")
- || strDirective.substring(1).equals("end")
- || strDirective.substring(1).equals("set")
- || strDirective.substring(1).equals("else")
- || strDirective.substring(1).equals("elseif")
- || strDirective.substring(1).equals("stop")
+ if ( dirTag.equals("if")
+ || dirTag.equals("end")
+ || dirTag.equals("set")
+ || dirTag.equals("else")
+ || dirTag.equals("elseif")
+ || dirTag.equals("stop")
)
{
bRecognizedDirective = true;
@@ -456,10 +459,11 @@
/*
* if that failed, lets lookahead to see if we matched a PD or a VM
*/
+ String nTag = t.next.image.substring(1);
- if ( isDirective( t.next.image.substring(1)))
+ if ( isDirective(nTag) )
control = true;
- else if ( rsvc.isVelocimacro( t.next.image.substring(1), currentTemplateName))
+ else if ( rsvc.isVelocimacro(nTag, currentTemplateName))
control = true;
jjtn000.val = "";
@@ -680,7 +684,7 @@
String directiveName;
if (t.kind == ParserConstants.BRACKETED_WORD)
{
- directiveName = t.image.substring(2,t.image.length() - 1);
+ directiveName = t.image.substring(2, t.image.length() - 1);
}
else
{
@@ -2576,11 +2580,6 @@
finally { jj_save(11, xla); }
}
- final private boolean jj_3R_47() {
- if (jj_3R_60()) return true;
- return false;
- }
-
final private boolean jj_3R_84() {
if (jj_3R_36()) return true;
return false;
@@ -2996,11 +2995,6 @@
return false;
}
- final private boolean jj_3_2() {
- if (jj_scan_token(DOUBLE_ESCAPE)) return true;
- return false;
- }
-
final private boolean jj_3R_34() {
if (jj_scan_token(IDENTIFIER)) return true;
Token xsp;
@@ -3011,6 +3005,11 @@
return false;
}
+ final private boolean jj_3_2() {
+ if (jj_scan_token(DOUBLE_ESCAPE)) return true;
+ return false;
+ }
+
final private boolean jj_3R_81() {
if (jj_scan_token(LPAREN)) return true;
return false;
@@ -3205,6 +3204,11 @@
return false;
}
+ final private boolean jj_3R_47() {
+ if (jj_3R_60()) return true;
+ return false;
+ }
+
public ParserTokenManager token_source;
public Token token, jj_nt;
private int jj_ntk;
@@ -3429,6 +3433,7 @@
final private void jj_rescan_token() {
jj_rescan = true;
for (int i = 0; i < 12; i++) {
+ try {
JJCalls p = jj_2_rtns[i];
do {
if (p.gen > jj_gen) {
@@ -3450,6 +3455,7 @@
}
p = p.next;
} while (p != null);
+ } catch(LookaheadSuccess ls) { }
}
jj_rescan = false;
}
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj?rev=685387&r1=685386&r2=685387&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/Parser.jj Tue Aug 12 17:03:19 2008
@@ -1,4 +1,4 @@
-/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. C:/Documents and Settings/wglass/My Documents/Workspace/misc/velocity/trunk/src/java/org/apache/velocity/runtime/parser\Parser.jj */
+/*@bgen(jjtree) Generated By:JJTree: Do not edit this line. .\Parser.jj */
/*@egen*//*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@@ -226,16 +226,19 @@
String strDirective = strImage.substring(iLast + 1);
boolean bRecognizedDirective = false;
+
+ // we don't have to call substring method all the time in this method
+ String dirTag = strDirective.substring(1);
/*
* is this a PD or a control directive?
*/
- if ( isDirective( strDirective.substring(1)))
+ if ( isDirective(dirTag) )
{
bRecognizedDirective = true;
}
- else if ( rsvc.isVelocimacro( strDirective.substring(1), currentTemplateName))
+ else if ( rsvc.isVelocimacro(dirTag, currentTemplateName))
{
bRecognizedDirective = true;
}
@@ -243,12 +246,12 @@
{
/* order for speed? */
- if ( strDirective.substring(1).equals("if")
- || strDirective.substring(1).equals("end")
- || strDirective.substring(1).equals("set")
- || strDirective.substring(1).equals("else")
- || strDirective.substring(1).equals("elseif")
- || strDirective.substring(1).equals("stop")
+ if ( dirTag.equals("if")
+ || dirTag.equals("end")
+ || dirTag.equals("set")
+ || dirTag.equals("else")
+ || dirTag.equals("elseif")
+ || dirTag.equals("stop")
)
{
bRecognizedDirective = true;
@@ -1246,10 +1249,11 @@
/*
* if that failed, lets lookahead to see if we matched a PD or a VM
*/
+ String nTag = t.next.image.substring(1);
- if ( isDirective( t.next.image.substring(1)))
+ if ( isDirective(nTag) )
control = true;
- else if ( rsvc.isVelocimacro( t.next.image.substring(1), currentTemplateName))
+ else if ( rsvc.isVelocimacro(nTag, currentTemplateName))
control = true;
jjtn000.val = "";
@@ -1463,8 +1467,8 @@
{
String directiveName;
if (t.kind == ParserConstants.BRACKETED_WORD)
- {
- directiveName = t.image.substring(2,t.image.length() - 1);
+ {
+ directiveName = t.image.substring(2, t.image.length() - 1);
}
else
{
Modified: velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java?rev=685387&r1=685386&r2=685387&view=diff
==============================================================================
--- velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java (original)
+++ velocity/engine/trunk/src/java/org/apache/velocity/runtime/parser/node/ASTObjectArray.java Tue Aug 12 17:03:19 2008
@@ -65,7 +65,8 @@
{
int size = jjtGetNumChildren();
- List objectArray = new ArrayList();
+ // since we know the amount of elements, initialize arraylist with proper size
+ List objectArray = new ArrayList(size);
for (int i = 0; i < size; i++)
{
Modified: velocity/engine/trunk/src/parser/Parser.jjt
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/src/parser/Parser.jjt?rev=685387&r1=685386&r2=685387&view=diff
==============================================================================
--- velocity/engine/trunk/src/parser/Parser.jjt (original)
+++ velocity/engine/trunk/src/parser/Parser.jjt Tue Aug 12 17:03:19 2008
@@ -247,16 +247,19 @@
String strDirective = strImage.substring(iLast + 1);
boolean bRecognizedDirective = false;
+
+ // we don't have to call substring method all the time in this method
+ String dirTag = strDirective.substring(1);
/*
* is this a PD or a control directive?
*/
- if ( isDirective( strDirective.substring(1)))
+ if ( isDirective(dirTag) )
{
bRecognizedDirective = true;
}
- else if ( rsvc.isVelocimacro( strDirective.substring(1), currentTemplateName))
+ else if ( rsvc.isVelocimacro(dirTag, currentTemplateName))
{
bRecognizedDirective = true;
}
@@ -264,12 +267,12 @@
{
/* order for speed? */
- if ( strDirective.substring(1).equals("if")
- || strDirective.substring(1).equals("end")
- || strDirective.substring(1).equals("set")
- || strDirective.substring(1).equals("else")
- || strDirective.substring(1).equals("elseif")
- || strDirective.substring(1).equals("stop")
+ if ( dirTag.equals("if")
+ || dirTag.equals("end")
+ || dirTag.equals("set")
+ || dirTag.equals("else")
+ || dirTag.equals("elseif")
+ || dirTag.equals("stop")
)
{
bRecognizedDirective = true;
@@ -1208,10 +1211,11 @@
/*
* if that failed, lets lookahead to see if we matched a PD or a VM
*/
+ String nTag = t.next.image.substring(1);
- if ( isDirective( t.next.image.substring(1)))
+ if ( isDirective(nTag) )
control = true;
- else if ( rsvc.isVelocimacro( t.next.image.substring(1), currentTemplateName))
+ else if ( rsvc.isVelocimacro(nTag, currentTemplateName))
control = true;
jjtThis.val = "";
@@ -1341,8 +1345,8 @@
{
String directiveName;
if (t.kind == ParserConstants.BRACKETED_WORD)
- {
- directiveName = t.image.substring(2,t.image.length() - 1);
+ {
+ directiveName = t.image.substring(2, t.image.length() - 1);
}
else
{