We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FilteredCollection
Maps#uniqueIndex
If values is a Collection, a presized builder is used in Maps#uniqueIndex (the change was introduced in this commit)
Collection
@CanIgnoreReturnValue public static <K, V> ImmutableMap<K, V> uniqueIndex( Iterable<V> values, Function<? super V, K> keyFunction) { if (values instanceof Collection) { return uniqueIndex( values.iterator(), keyFunction, ImmutableMap.builderWithExpectedSize(((Collection<?>) values).size())); } return uniqueIndex(values.iterator(), keyFunction); }
However, for FilteredCollection, calling size() results in applying the predicate to all the elements of the unfiltered collection (link)
size()
predicate
unfiltered
@Override public int size() { int size = 0; for (E e : unfiltered) { if (predicate.apply(e)) { size++; } } return size; }
To prevent applying the predicate an additional time , presized builder should not be used if values is a FilteredCollection or FilteredMultimapValues
values
FilteredMultimapValues
The text was updated successfully, but these errors were encountered:
The suggested fix is implemented in this pull request: PicnicSupermarket#27
Sorry, something went wrong.
lowasser
No branches or pull requests
If values is a
Collection
, a presized builder is used in Maps#uniqueIndex (the change was introduced in this commit)However, for
FilteredCollection
, callingsize()
results in applying thepredicate
to all the elements of theunfiltered
collection (link)To prevent applying the predicate an additional time , presized builder should not be used if
values
is aFilteredCollection
orFilteredMultimapValues
The text was updated successfully, but these errors were encountered: