liballoc: VecDeque: Simplify binary_search_by()

This commit is contained in:
Vojtech Kral 2020-10-16 20:24:49 +02:00
parent e0506d1e9a
commit c7a787a327
1 changed files with 4 additions and 15 deletions

View File

@ -2516,24 +2516,13 @@ impl<T> VecDeque<T> {
where where
F: FnMut(&'a T) -> Ordering, F: FnMut(&'a T) -> Ordering,
{ {
if self.is_empty() {
return Err(0);
}
let (front, back) = self.as_slices(); let (front, back) = self.as_slices();
match back.first().map(|elem| f(elem)) { if let Some(Ordering::Less | Ordering::Equal) = back.first().map(|elem| f(elem)) {
Some(Ordering::Equal) => return Ok(front.len()), back.binary_search_by(f).map(|idx| idx + front.len()).map_err(|idx| idx + front.len())
Some(Ordering::Less) => { } else {
return back[1..] front.binary_search_by(f)
.binary_search_by(f)
.map(|idx| idx + front.len() + 1)
.map_err(|idx| idx + front.len() + 1);
}
_ => {}
} }
front.binary_search_by(f)
} }
/// Binary searches this sorted `VecDeque` with a key extraction function. /// Binary searches this sorted `VecDeque` with a key extraction function.