Skip to content

Commit

Permalink
Optimise Iter::{size_hint, count} for events::Iter
Browse files Browse the repository at this point in the history
This replaces the default implementation with an optimised one.
  • Loading branch information
Thomasdezeeuw committed May 10, 2020
1 parent b15fc18 commit 40df934
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/event/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ impl<'a> Iterator for Iter<'a> {
self.pos += 1;
ret
}

fn size_hint(&self) -> (usize, Option<usize>) {
let size = self.inner.inner.len();
(size, Some(size))
}

fn count(self) -> usize {
self.inner.inner.len()
}
}

impl fmt::Debug for Events {
Expand Down
4 changes: 4 additions & 0 deletions src/sys/windows/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ impl Events {
self.events.capacity()
}

pub fn len(&self) -> usize {
self.events.len()
}

pub fn get(&self, idx: usize) -> Option<&Event> {
self.events.get(idx)
}
Expand Down

0 comments on commit 40df934

Please sign in to comment.