On Fri, 21 Aug 2026 20:01:39 GMT, Andy Goryachev <[email protected]> wrote:
>> Okay, but then `TreeSet` is the worst option since it allocates a new >> red-black tree node for every element. `Stream.sorted(Comparator)` doesn't >> do that, it puts all elements into an array and sorts that. >> But the absolute lowest overhead version of them all is probably `List.sort`: >> >> List<PseudoClass> pseudoClasses = new >> ArrayList<>(selector.getPseudoClassStates()); >> pseudoClasses.sort(Comparator.comparing(PseudoClass::getPseudoClassName)); > > how many pseudoclasses so we have in a selector, realistically speaking? a > few, really. > > but there was one issue with my code - no sorting is necessary if the number > of pseudoclasses is less than 2. I would also rather like to see a `List` here. Right now, `Set<PseudoClass> pseudoClassStates = selector.getPseudoClassStates();` reads like we do not care about the order, just to see that we do care about it right after by using a `TreeSet`. IMO we should not have a `Set` at all here, so if we for example write: `List<PseudoClass> pseudoClassStates = selector.getPseudoClassStates().stream().sorted(Comparator.comparing(PseudoClass::getPseudoClassName)).toList();`, it is immediately clear that we care about the order and we always use a `List`, never a `Set`. ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/2271#discussion_r3839208426
