RFR 7065380 : Allow Collections.sort to sort Collections.singletonList() result
Rémi Forax
forax at univ-mlv.fr
Thu Mar 1 21:00:56 UTC 2012
On 03/01/2012 09:52 PM, Vitaly Davidovich wrote:
>
> I thought so too initially but that's optimizing for empty or
> singleton collections which probably are an edge case? Adding a
> branch, polymorphic method call, and increasing bytecode size may not
> be worth it.
>
toArray is also polymorphic, so the typecheck will be done once :)
On 03/01/2012 09:56 PM, Vitaly Davidovich wrote:
>
> Also some collections may not have an O(1) size().
>
> Sent from my phone
>
Yes, you're right. I see now.
Rémi
> Sent from my phone
>
> On Mar 1, 2012 3:25 PM, "Rémi Forax" <forax at univ-mlv.fr
> <mailto:forax at univ-mlv.fr>> wrote:
>
> On 03/01/2012 08:50 PM, Mike Duigou wrote:
>
> Hello all;
>
> Currently Collections.sort() refuses to sort the lists which
> result from calling Collections.singletonList(). This makes
> some sense because the singleton lists are immutable but they
> are also alway sorted.
>
> This patch allows Collections.sort() to be used with empty and
> singleton lists of all types. A short circuit return is
> provided for lists of length 0 and 1 as they are already sorted.
>
> WEBREV: http://cr.openjdk.java.net/~mduigou/7065380/0/webrev/
> <http://cr.openjdk.java.net/%7Emduigou/7065380/0/webrev/>
>
> For the unit test ignore the diffs and view the "New"
> file--webrev doesn't understand "hg copy".
>
> Thanks,
>
> Mike
>
>
> Is it not better to check list.size() before calling toArray() ?
>
> Rémi
>
More information about the core-libs-dev
mailing list