RFR: 8267844: Replace Integer/Long.valueOf() with Integer/Long.parse*() where applicable
Сергей Цыпанов
github.com+10835776+stsypanov at openjdk.java.net
Tue Aug 10 17:43:15 UTC 2021
On Tue, 10 Aug 2021 14:56:11 GMT, Claes Redestad <redestad 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.
>
> 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).
Good point! Let me check this.
-------------
PR: https://git.openjdk.java.net/jdk/pull/5068
More information about the security-dev
mailing list