On Mon, 20 Jun 2022 09:11:31 GMT, Attila Szegedi <att...@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. This behaves slightly different from the old initialization; the concurrent hash map blocks when the mapping function is run, just in case if non-blocking instantiation is what we want. If that's not a problem, I would prefer szegedi's suggestion. ------------- PR: https://git.openjdk.org/jdk/pull/9208