Even though the implementation of java.io.BufferedReader in the JDK
1.3 is internally fairly performant when reading short streams, there
isn't even a point in creating one if our input data is smaller than
BufferedReader's internal buffer. In the worst case scenario
(probably the common case), this patch nets a savings of at least 2
stack frame pushes.
Index: Velocity.java
===================================================================
RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/app/Velocity.java,v
retrieving revision 1.23
diff -u -u -r1.23 Velocity.java
--- Velocity.java 2001/09/07 05:05:14 1.23
+++ Velocity.java 2001/10/22 21:03:53
@@ -250,7 +250,12 @@
throws ParseErrorException, MethodInvocationException,
ResourceNotFoundException, IOException
{
- return evaluate( context, out, logTag, new BufferedReader( new StringReader(
instring )) );
+ Reader reader = new StringReader(instring);
+ if (instring.length() > 8192)
+ {
+ reader = new BufferedReader(reader);
+ }
+ return evaluate(context, out, logTag, reader);
}
/**