Minor stylistic fixes.

This commit is contained in:
whitequark 2018-05-24 21:17:37 +00:00
parent 4299b43859
commit 1328e59fc7
1 changed files with 22 additions and 20 deletions

View File

@ -139,15 +139,16 @@ fn binary_search_by_key_range<'a, K, V, Q: 'a, R>(slice: &[Option<(K, V)>], rang
// any of these guarantees. // any of these guarantees.
// Find the beginning // Find the beginning
let begin = if let Bound::Unbounded = range.start() { let begin;
0 if let Bound::Unbounded = range.start() {
begin = 0;
} else { } else {
macro_rules! is_before_range { macro_rules! is_before_range {
( $item: expr) => { ( $item: expr) => {
match &range.start() { match &range.start() {
Bound::Included(ref key_begin) => $item < Some(key_begin.borrow()), Bound::Included(ref key_begin) => $item < Some(key_begin.borrow()),
Bound::Excluded(ref key_begin) => $item <= Some(key_begin.borrow()), Bound::Excluded(ref key_begin) => $item <= Some(key_begin.borrow()),
Bound::Unbounded => unreachable!(), Bound::Unbounded => unreachable!()
} }
} }
}; };
@ -159,25 +160,26 @@ fn binary_search_by_key_range<'a, K, V, Q: 'a, R>(slice: &[Option<(K, V)>], rang
right = middle - 1; right = middle - 1;
} else { } else {
left = middle; left = middle;
break; break
} }
} }
if left == slice.len() || is_before_range!(key!(slice[left])) { if left == slice.len() || is_before_range!(key!(slice[left])) {
return Err(()) return Err(())
} }
left begin = left
}; };
// Find the ending // Find the ending
let end = if let Bound::Unbounded = range.end() { let end;
slice.len() if let Bound::Unbounded = range.end() {
end = slice.len()
} else { } else {
macro_rules! is_after_range { macro_rules! is_after_range {
( $item:expr ) => { ( $item:expr ) => {
match &range.end() { match &range.end() {
Bound::Included(ref key_end) => $item > Some(key_end.borrow()), Bound::Included(ref key_end) => $item > Some(key_end.borrow()),
Bound::Excluded(ref key_end) => $item >= Some(key_end.borrow()), Bound::Excluded(ref key_end) => $item >= Some(key_end.borrow()),
Bound::Unbounded => unreachable!(), Bound::Unbounded => unreachable!()
} }
} }
}; };
@ -190,13 +192,13 @@ fn binary_search_by_key_range<'a, K, V, Q: 'a, R>(slice: &[Option<(K, V)>], rang
left = middle + 1; left = middle + 1;
} else { } else {
right = middle; right = middle;
break; break
} }
} }
if right == 0 || is_after_range!(key!(slice[right - 1])) { if right == 0 || is_after_range!(key!(slice[right - 1])) {
return Err(()) return Err(())
} }
right end = right
}; };
Ok((begin, end)) Ok((begin, end))