On Tue, 15 Aug 2023 19:33:20 GMT, John Hendrikx <jhendr...@openjdk.org> wrote:
>> modules/javafx.graphics/src/main/java/com/sun/javafx/css/ImmutablePseudoClassSetsCache.java >> line 61: >> >>> 59: CACHE.put(copy, copy); >>> 60: >>> 61: return copy; >> >> Isn't this just `return CACHE.computeIfAbsent(pseudoClasses, Set::copyOf);`? > > Almost, but the key is also the copied set. In your version the key is the > original object, which may be a modifiable set. If the key is modified, the > cache will not function correctly anymore. > > I had a different version before, but @mstr2 pointed out that there was an > unnecessary allocation in that version which this version avoids. Then the map is just an optimization? If the set points to itself then a `Set` as a cache should be enough. ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/1076#discussion_r1295381418