On Thu, 30 Mar 2023 19:38:39 GMT, Michael Strauß <mstra...@openjdk.org> wrote:
> Do we want to depend on this behavior? The specification of `Set.copyOf` says: > > ``` > @implNote > If the given Collection is an unmodifiable Set, calling copyOf will generally > not create a copy. > ``` > > While the actual implementation _never_ creates a copy if the given > collection is immutable, the specification does not guarantee that in all > cases, but only in the general case. This behavior could theoretically change > without changing the specification of `Set.copyOf`. If it ever changes implementation, I suppose we could do this logic ourselves -- however, you did give me an idea... before making the copy, I could check if it is in the cache already. In the case that the set you pass is mutable, but I have an immutable copy already then no copy would need to be made. The only time a copy is made then is if it wasn't in the cache yet. Before arriving at this solution I had a class `ImmutablePseudoClassState` which extended `AbstractSet`. But after stripping everything out that I didn't need, the only thing that was left was a single private field... which was also a `Set`. I then concluded that there is no need for this wrapper at all, as everything in the CSS code can deal with `Set<PseudoClass>` directly. ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/1076#discussion_r1153751462