Simplify implementation of ordered_get.

This commit is contained in:
Markus Reiter 2025-04-06 17:55:22 +02:00
parent 2f0008b4ca
commit a795502288
No known key found for this signature in database

View File

@ -527,16 +527,7 @@ impl<T, S: HistBufStorage<T> + ?Sized> HistoryBufferInner<T, S> {
/// assert_eq!(buffer.ordered_get(6), None);
/// ```
pub fn ordered_get(&self, idx: usize) -> Option<&T> {
if self.len() <= idx {
None
} else {
let (front, back) = self.as_slices();
if idx < front.len() {
Some(&front[idx])
} else {
Some(&back[idx - front.len()])
}
}
self.oldest_ordered().nth(idx)
}
/// Returns double ended iterator for iterating over the buffer from