refactor: Prefer match on the result of cmp to if/else if/else chains

pull/24376/head
Carol (Nichols || Goulding) 2020-03-27 15:52:51 -04:00
parent 1247544deb
commit 2eb09f29ef
2 changed files with 26 additions and 20 deletions

View File

@ -1,6 +1,5 @@
#![deny(rust_2018_idioms)]
#![warn(clippy::explicit_iter_loop)]
#![allow(clippy::comparison_chain)]
use std::{error, fmt};

View File

@ -6,6 +6,7 @@ use crate::storage::series_store::ReadPoint;
use crate::storage::StorageError;
use futures::stream::{BoxStream, Stream};
use std::cmp::Ordering;
use std::mem;
use std::pin::Pin;
use std::task::{Context, Poll};
@ -125,14 +126,16 @@ impl Stream for StringMergeStream<'_> {
next_val = Some(val.clone());
next_pos = pos;
}
(Some(next), Poll::Ready(Some(ref val))) => {
if next > val {
(Some(next), Poll::Ready(Some(ref val))) => match next.cmp(val) {
Ordering::Greater => {
next_val = Some(val.clone());
next_pos = pos;
} else if next == val {
}
Ordering::Equal => {
state.next = state.stream.as_mut().poll_next(cx);
}
}
_ => (),
},
(Some(_), Poll::Ready(None)) => (),
(None, Poll::Ready(None)) => (),
_ => unreachable!(),
@ -218,23 +221,27 @@ impl Stream for ReadMergeStream<'_> {
min_time = t;
}
(Some(min_key), Poll::Ready(Some(batch))) => {
if min_key > &batch.key {
next_min_key = Some(batch.key.clone());
min_pos = pos;
positions = Vec::with_capacity(self.states.len());
let (_, t) = batch.start_stop_times();
min_time = t;
} else if min_key == &batch.key {
// if this batch has an end time less than the existing min time, make this
// the batch that we want to pull out first
let (_, t) = batch.start_stop_times();
if t < min_time {
min_time = t;
positions.push(min_pos);
match min_key.cmp(&batch.key) {
Ordering::Greater => {
next_min_key = Some(batch.key.clone());
min_pos = pos;
} else {
positions.push(pos);
positions = Vec::with_capacity(self.states.len());
let (_, t) = batch.start_stop_times();
min_time = t;
}
Ordering::Equal => {
// if this batch has an end time less than the existing min time, make this
// the batch that we want to pull out first
let (_, t) = batch.start_stop_times();
if t < min_time {
min_time = t;
positions.push(min_pos);
min_pos = pos;
} else {
positions.push(pos);
}
}
_ => (),
}
}
(Some(_), Poll::Ready(None)) => (),