<i18n dev> RFR: 8288723: Avoid redundant ConcurrentHashMap.get call in java.time [v2]
Attila Szegedi
attila at openjdk.org
Sun Jul 3 19:51:22 UTC 2022
On Wed, 22 Jun 2022 21:29:50 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:
>> Instead of separate ConcurrentHashMap.get call, we can use result of previous putIfAbsent call.
>
> Andrey Turbanov has updated the pull request incrementally with one additional commit since the last revision:
>
> 8288723: Avoid redundant ConcurrentHashMap.get call in java.time
> use computeIfAbsent where lambda could be short and static
Few more thoughts.
src/java.base/share/classes/java/time/ZoneOffset.java line 435:
> 433: result = prev;
> 434: }
> 435: ID_CACHE.putIfAbsent(result.getId(), result);
Feel free to ignore this one, but you could still have this be a `computeIfAbsent` and put the ID_CACHE.putIfAbsent part in the lambda. Yeah, there'll be more work done inside of `computeIfAbsent` but I think it's an acceptable tradeoff for a more comprehensible code.
src/java.base/share/classes/java/time/format/DecimalStyle.java line 163:
> 161: public static DecimalStyle of(Locale locale) {
> 162: Objects.requireNonNull(locale, "locale");
> 163: return CACHE.computeIfAbsent(locale, l -> create(l));
Suggestion:
return CACHE.computeIfAbsent(locale, DecimalStyle::create);
-------------
Changes requested by attila (Reviewer).
PR: https://git.openjdk.org/jdk/pull/9208
More information about the i18n-dev
mailing list