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

Specialize "loops of next" #818

Merged
Merged
Changes from 1 commit
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
9 changes: 5 additions & 4 deletions src/unique_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,15 @@ where
I::Item: Eq + Hash + Clone,
{
fn next_back(&mut self) -> Option<Self::Item> {
while let Some(v) = self.iter.iter.next_back() {
if let Entry::Vacant(entry) = self.iter.used.entry(v) {
let UniqueBy { iter, used, .. } = &mut self.iter;
iter.rev().find_map(|v| {
Copy link
Member

Choose a reason for hiding this comment

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

Off-topic: Is it strange that there's rfind, but no rfind_map?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's not off-topic to me. I was wondering the same question while writing this.
Maybe there is no large performance gain to expect compare to .rev().method(). I searched a bit but did not find anything.
More generally, DoubleEndedIterator does not have a lot of methods.

if let Entry::Vacant(entry) = used.entry(v) {
let elt = entry.key().clone();
entry.insert(());
return Some(elt);
}
}
None
None
})
}
}

Expand Down