<i18n dev> RFR: 8288723: Avoid redundant ConcurrentHashMap.get call in java.time

Attila Szegedi attila at openjdk.org
Mon Jun 20 09:51:56 UTC 2022

On Sat, 18 Jun 2022 10:43:08 GMT, Andrey Turbanov <aturbanov at openjdk.org> wrote:

> Instead of separate ConcurrentHashMap.get call, we can use result of previous putIfAbsent call.

src/java.base/share/classes/java/time/format/DateTimeTextProvider.java line 319:

> 317:                 store = prev;
> 318:             }
> 319:         }

You could do better here and use `computeIfAbsent` with `createStore` as its lambda. You could even change the signature of `createStore` to take `Entry<TemporalField, Locale>` as its parameter and then you could have this method be:

    private Object findStore(TemporalField field, Locale locale) {
        return CACHE.computeIfAbsent(createEntry(field, locale), this::createStore);


    private Object createStore(Entry<TemporalField, Locale> entry) {

This applies to most other changes you made, the one in `ZoneOffset` is the only one that's slightly different because there you have adjustment of `ID_CACHE` too.


PR: https://git.openjdk.org/jdk/pull/9208

More information about the i18n-dev mailing list