-
Notifications
You must be signed in to change notification settings - Fork 613
New issue
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
Perf Issue: toImmutable[List/Set/Bag] methods should be overridden on LazyIterable #1587
Comments
Hello, I would like to work on this issue! |
This comment was marked as resolved.
This comment was marked as resolved.
To avoid confusion with my hidden comment: Tomorrow I will create a pull request with a solution for the issue. |
I was going to say that the implementation should use toArray() /**
* Converts the LazyIterable to the default ImmutableList implementation.
*/
@Override
default ImmutableList<T> toImmutableList()
{
T[] array = (T[]) this.toArray();
return Lists.immutable.with(array);
}
/**
* Converts the LazyIterable to the default ImmutableSet implementation.
*/
@Override
default ImmutableSet<T> toImmutableSet()
{
T[] array = (T[]) this.toArray();
return Sets.immutable.with(array);
}
/**
* Converts the LazyIterable to the default ImmutableBag implementation.
*/
@Override
default ImmutableBag<T> toImmutableBag()
{
T[] array = (T[]) this.toArray();
return Bags.immutable.with(array);
} However I see that toArray() has the same problem and needs to be fixed too. @Override
public Object[] toArray()
{
Object[] result = new Object[this.size()];
this.forEachWithIndex((each, index) -> result[index] = each);
return result;
} |
The default implementations of
toImmutable[List/Set/Bag]
are suboptimal forLazyIterable
. Calls toisEmpty
orsize
should be avoided forLazyIterable
as they will force iteration to happen. The following tests will fail currently and should be added with appropriate fixes, which should probably be just overriding withdefault
methods inLazyIterable
.The text was updated successfully, but these errors were encountered: