<i18n dev> RFR: 8345668: ZoneOffset.ofTotalSeconds performance regression [v2]
Naoto Sato
naoto at openjdk.org
Fri Dec 20 20:58:22 UTC 2024
On Fri, 20 Dec 2024 20:25:28 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> Naoto Sato has updated the pull request incrementally with one additional commit since the last revision:
>>
>> Update src/java.base/share/classes/java/time/ZoneOffset.java
>>
>> Co-authored-by: Roger Riggs <Roger.Riggs at Oracle.com>
>
> src/java.base/share/classes/java/time/ZoneOffset.java line 432:
>
>> 430: result = new ZoneOffset(totalSeconds);
>> 431: SECONDS_CACHE.putIfAbsent(totalSecs, result);
>> 432: result = SECONDS_CACHE.get(totalSecs);
>
> putIfAbsent() returns the existing value (if any), the 2nd get can be avoided by using the non-null value if returned or returning the result just created.
> Suggestion:
>
> var existing = SECONDS_CACHE.putIfAbsent(totalSecs, result);
> return (existing != null) ? existing : result;
>
> It should perform better than doing the `get` again.
That's right. Committed as suggested
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/22854#discussion_r1894382433
More information about the i18n-dev
mailing list