1
Fork 0

Eliminate a token clone from advance_left

This commit is contained in:
David Tolnay 2022-01-19 18:35:02 -08:00
parent d81740ed2a
commit d981c5b354
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 7 additions and 7 deletions

View file

@ -32,11 +32,6 @@ impl<T> RingBuffer<T> {
index
}
pub fn advance_left(&mut self) {
self.data.pop_front().unwrap();
self.offset += 1;
}
pub fn clear(&mut self) {
self.data.clear();
}
@ -53,6 +48,12 @@ impl<T> RingBuffer<T> {
self.data.front_mut()
}
pub fn pop_first(&mut self) -> Option<T> {
let first = self.data.pop_front()?;
self.offset += 1;
Some(first)
}
pub fn last(&self) -> Option<&T> {
self.data.back()
}