On Tue, 28 Jun 2022 07:27:30 GMT, Andrey Turbanov <aturba...@openjdk.org> wrote:
>> src/java.base/share/classes/java/time/temporal/WeekFields.java line 331: >> >>> 329: String key = firstDayOfWeek.toString() + >>> minimalDaysInFirstWeek; >>> 330: WeekFields rules = CACHE.get(key); >>> 331: if (rules == null) { >> >> Perhaps you don't even need this `if` block and the preceding >> `CACHE.get(key)` and maybe it can be replaced with: >> >> >> return CACHE.computeIfAbsent(key, ignore -> new WeekFields(firstDayOfWeek, >> minimalDaysInFirstWeek)); > > But it will generate garbage: non-static lambda. It already generates some garbage as it does string concatenation for the key. Here's an idea: declare a record class for the key, `record CacheKey(DayOfWeek firstDayOfWeek, int minimalDaysInFirstWeek)`. It will be more efficient than using strings for keys, and then you can have a static lambda. ------------- PR: https://git.openjdk.org/jdk/pull/9208