On Tue, 10 Aug 2021 14:56:11 GMT, Claes Redestad <redes...@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

Reply via email to