Skip to content

In, AutowireUtils.sortConstructors(), Using valueOf is faster than using constructor [SPR-12385] #16993

@spring-projects-issues

Description

@spring-projects-issues

Kang Baek-Kyu opened SPR-12385 and commented

Using valueOf is approximately 3.5 times faster than using constructor

Because 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.

So changed source like this

return (new Integer(c1pl)).compareTo(c2pl) * -1;
==>return (Integer.valueOf(c1pl)).compareTo(c2pl) * -1;


Affects: 4.1.1

Reference URL: #682

Referenced from: commits 4945cf1

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions