-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
iter::Flatten, FlatMap should return more precise size_hint and be TrustedLen when item type is an array #87094
Comments
It does a bit better than that. Collecting into a rust/library/alloc/src/vec/mod.rs Lines 2550 to 2562 in b5a2cce
But yes, we should be able to do better for array::IntoIter. |
Only a bit better: let _ = iter.next();
println!("{:?}", iter.size_hint()); results in |
I don't think you can that much better for However this doesn't apply when you directly return an array because they can't be advanced, so the adapter can know the exact number of elements they have. |
Yeah, sorry, that's what I meant. |
If I understand correctly, presence of
TrustedLen
trait allows.collect::<Vec<_>>()
to avoid reallocations, right?In that case, given the following:
Since the type I map to has known const size (
[u8; 4]
), size_hint should be able to precisely return(40, Some(40))
, and the iterator specialization should implement TrustedLen.Currently, it returns
(0, None)
. This means that to implement this function efficiently, I'd need to manually doVec::with_capacity(pixels.len() * 4)
.The text was updated successfully, but these errors were encountered: