RFR: 8267844: Replace Integer/Long.valueOf() with Integer/Long.parse*() where applicable

Claes Redestad redestad at openjdk.java.net
Tue Aug 10 15:00:37 UTC 2021

On Tue, 10 Aug 2021 13:16:42 GMT, Сергей Цыпанов <github.com+10835776+stsypanov at openjdk.org> wrote:

> The code in `Integer.decode()` and `Long.decode()` might allocate two instances of Integer/Long for the negative values less than -127:
> Integer result;
> result = Integer.valueOf(nm.substring(index), radix);
> result = negative ? Integer.valueOf(-result.intValue()) : result;
> To avoid this we can declare 'result' as `int` and use `Integer.parseInt()` method. Same applicable for `Long` and some other classes.

Looks fine to me.

Could you consider adding microbenchmarks for Integer/Long.decode?

src/java.base/share/classes/java/lang/Integer.java line 1450:

> 1448: 
> 1449:         try {
> 1450:             result = parseInt(nm.substring(index), radix);

Possibly a follow-up, but I think using `parseInt/-Long(nm, index, nm.length(), radix)` could give an additional speed-up in these cases (by avoiding a substring allocation).


Marked as reviewed by redestad (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/5068

More information about the security-dev mailing list