That's only because toSet() creates a LinkedHashSet. Perhaps it could be optimized to create a specialized Set that just keeps the range as its only property and whose
contains
method just forwards to the range, and defines a suitably specialized
containsAll
. Then the above code would have good performance.
Or perhaps just a new