Skip to content
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

Avoid excessive reallocations during item-bodies checking #31929

Merged
merged 1 commit into from
Feb 27, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/librustc/middle/subst.rs
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,11 @@ impl<'a,T> Iterator for EnumeratedItems<'a,T> {
None
}
}

fn size_hint(&self) -> (usize, Option<usize>) {
let size = self.vec.as_slice().len();
(size, Some(size))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This overestimates the number of elements in the iterator, doesn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. The underlying vector is used in its entirety. If you check VecPerParamSpace::limits() one can see how it is split into three consecutive ranges.

(We discussed this on IRC, I'm just adding this comment for reference.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I now understand the iterator! It's fine. We cleared this up on irc.

}
}

impl<T> IntoIterator for VecPerParamSpace<T> {
Expand Down