Bug 58547 - Avoid new Integer and new Long instances when doing conversions
Summary: Avoid new Integer and new Long instances when doing conversions
Status: RESOLVED FIXED
Alias: None
Product: Tomcat 8
Classification: Unclassified
Component: Util (show other bugs)
Version: 8.0.x-trunk
Hardware: Macintosh Mac OS X 10.1
: P2 trivial (vote)
Target Milestone: ----
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-10-25 23:22 UTC by Anthony Whitford
Modified: 2015-10-27 11:01 UTC (History)
0 users



Attachments
Replaced new Integer/Long with valueOf calls (4.44 KB, patch)
2015-10-25 23:22 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 2015-10-25 23:22:01 UTC
Created attachment 33219 [details]
Replaced new Integer/Long with valueOf calls

Discovered cases where an inefficient Number constructor is being called instead of the static valueOf.

Using new Integer(int) is guaranteed to always result in a new object whereas Integer.valueOf(int) allows caching of values to be done by the compiler, class library, or JVM. Using of cached values avoids object allocation and the code will be faster.

See http://findbugs.sourceforge.net/bugDescriptions.html#DM_NUMBER_CTOR
Comment 1 Violeta Georgieva 2015-10-27 11:01:30 UTC
Hi,

Thanks for the report and the patch.
I applied the same fix on other places in the code also.
The fix is available in trunk, 8.0.x (for 8.0.29 onwards) and 7.0.x (for 7.0.66
onwards)

Regards,
Violeta