Bug 46819 - Remove redundant object instantiations in JspRuntimeLibrary
Remove redundant object instantiations in JspRuntimeLibrary
Status: RESOLVED FIXED
Product: Tomcat 6
Classification: Unclassified
Component: Jasper
6.0.18
PC Windows Vista
: P2 enhancement (vote)
: default
Assigned To: Tomcat Developers Mailing List
:
Depends on:
Blocks:
  Show dependency tree
 
Reported: 2009-03-07 23:30 UTC by Anthony Whitford
Modified: 2011-01-28 18:24 UTC (History)
0 users



Attachments
Patch file to replace new with valueOf, and some valueOf with parse (9.13 KB, patch)
2009-03-07 23:30 UTC, Anthony Whitford
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Anthony Whitford 2009-03-07 23:30:10 UTC
Created attachment 23353 [details]
Patch file to replace new with valueOf, and some valueOf with parse

While perusing the code, I noticed that java\org\apache\jasper\runtime\JspRuntimeLibrary.java code was doing a few things that I think can be improved:

1.  coerce methods were instantiating new objects, only to convert them to primitives.  For example:

    return Boolean.valueOf(s).booleanValue();

This can be rewritten (and simplified) as:

    return Boolean.parseBoolean(s);

This pattern was repeated for numerous primitive types.


2.  Objects were being instantiated using new instead of calling valueOf.  For example:

    return new Byte((byte) 0);

instead of:

    return Byte.valueOf((byte) 0);

According to the Java API, valueOf should generally be used in preference to the constructor as this method is likely to yield significantly better space and time performance.

3.  toString methods are instantiating a temporary object just to turn it into a string value.  For example:

    return new Integer(i).toString();

This can be rewritten (and simplified) as:

    return Integer.toString(i);

This pattern was repeated for numerous primitive types.


I took the liberty of creating a patch.  These changes should yield improved performance and reduce the memory footprint.
Comment 1 Mark Thomas 2011-01-28 18:24:55 UTC
The patch has been applied to 7.0.x and will be included in 7.0.7 onwards.

There are no plans to back-ported it to 6.0.x.