maidh91 / guava-libraries

Automatically exported from code.google.com/p/guava-libraries
Apache License 2.0
0 stars 0 forks source link

Ordering.immutableSortedCopy() #326

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Like Ordering.sortedCopy(), but returns an ImmutableList (and can't allow 
nulls).

I can't believe we haven't added this yet.

Original issue reported on code.google.com by kevinb@google.com on 12 Feb 2010 at 5:01

GoogleCodeExporter commented 9 years ago
r03

Original comment by kevinb@google.com on 9 Apr 2010 at 5:41

GoogleCodeExporter commented 9 years ago
The implementation of this copies the specified Iterable into a new ArrayList 
twice--once for the sort, and then again to create a defensive copy when 
creating the ImmutableList.

This seems wasteful because both classes making the copy are inside Guava.

There's no ideal way to improve this but two options are

1. Introduce package-private factory methods that bypass the defensive copying

2. Add a copyOf(Iterable, Ordering) method that will sort the array before 
passing into construct().

I know this is low-priority but it can add up.

Original comment by ori.schw...@gmail.com on 4 May 2012 at 9:40

GoogleCodeExporter commented 9 years ago
I will investigate to see if there's actually a nonnegligible performance 
improvement.

Original comment by wasserman.louis on 4 May 2012 at 10:02

GoogleCodeExporter commented 9 years ago
In Feb 2010 we actually did add a package-private ImmutableList.backedBy(E[]) 
method, but then we backed out of it. We never found more than one safe place 
we could use it, and we caused bugs by using it unsafely. Part of the problem 
might have been keeping track of who's responsible for the null checking? Dunno.

Original comment by kevinb@google.com on 4 May 2012 at 10:14

GoogleCodeExporter commented 9 years ago
Um. We currently have ImmutableList.asImmutableList(Object[]) already as 
package-private.  Sending in a CL to use it.

Original comment by wasserman.louis on 7 May 2012 at 2:34

GoogleCodeExporter commented 9 years ago
This issue has been migrated to GitHub.

It can be found at https://github.com/google/guava/issues/<id>

Original comment by cgdecker@google.com on 1 Nov 2014 at 4:15

GoogleCodeExporter commented 9 years ago

Original comment by cgdecker@google.com on 3 Nov 2014 at 9:10