RFR 7065380 : Allow Collections.sort to sort Collections.singletonList() result
Jason Mehrens
jason_mehrens at hotmail.com
Tue Mar 13 22:11:21 UTC 2012
> Well it's not a bug it is a RFE. :) But I agree that the example is a
> little flawed in that generate() would not reasonably be able to
> generate mutable lists in some cases and immutable lists in others.
> I find the restriction on empty/singleton lists unnecessary, but not
> sure it is worth jumping through the spec hoops to change this.
Agreed.
If the core of this RFE is to allow just Collections.singletonList to work then one possible fix would be to relax SingletonList.set to be a no-op if the given element is the contained element (see CopyOnWriteList.set). That way there is no performance impact for everyone else calling sort. The spec for SingletonList would have to change which might be a deal breaker. If not, then this RFE is really about allowing sort to return normally for pre-sorted unmodifiable lists and Collections.singletonList fits that category. For this case, sort could prevent swaps of identical elements. But, that's a sort spec change and a lot of performance testing.
Jason
More information about the core-libs-dev
mailing list