liballoc: VecDeque: Simplify binary_search_by()
This commit is contained in:
parent
e0506d1e9a
commit
c7a787a327
|
@ -2516,25 +2516,14 @@ 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..]
|
|
||||||
.binary_search_by(f)
|
|
||||||
.map(|idx| idx + front.len() + 1)
|
|
||||||
.map_err(|idx| idx + front.len() + 1);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
front.binary_search_by(f)
|
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.
|
||||||
///
|
///
|
||||||
|
|
Loading…
Reference in New Issue