On Tue, 10 Aug 2021 13:16:42 GMT, Сергей Цыпанов
<[email protected]> 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