TimurMahammadov / google-collections

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

Don't re-iterate across the same iterable unnecessarily #67

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
ImmutableList.copyOf(Iterable) has the following issue. If the provided
iterable isn't a collection, that method iterates across the elements
twice, once to determine the size and once to store the elements in the
ImmutableList.

That hurts performance if, for example, the iterable reads rows from a
database. Also, the code can fail if second iteration has fewer elements
than the first, as can happen if the underlying data changes.

I've fixed the ImmutableList code, and that code change is currently being
reviewed. However, the same problem exists elsewhere in the library.

Note that a separate problem exists when a concurrent collection is
provided as input, since a concurrent modification can lead to count()
differing from the number of elements appearing in a subsequent iteration.

Original issue reported on code.google.com by jared.l....@gmail.com on 21 May 2008 at 5:24

GoogleCodeExporter commented 9 years ago

Original comment by kevin...@gmail.com on 27 May 2008 at 7:16

GoogleCodeExporter commented 9 years ago
I believe we've addressed this in all our Iterable-accepting libraries now, 
with my
latest fix to Iterables.partition().

Original comment by kevin...@gmail.com on 11 Feb 2009 at 12:55