From b2cdd299f56d8de7e2e643f6ca9ede4346bfa4ef Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Fri, 14 Feb 2020 17:13:05 +0000 Subject: [PATCH 1/5] refactor: apply clippy --- src/encoders/float.rs | 151 +++++++++++++++++++------------------- src/encoders/integer.rs | 20 ++--- src/encoders/simple8b.rs | 2 +- src/encoders/timestamp.rs | 24 +++--- 4 files changed, 98 insertions(+), 99 deletions(-) diff --git a/src/encoders/float.rs b/src/encoders/float.rs index fcd73ef891..ec2b39e708 100644 --- a/src/encoders/float.rs +++ b/src/encoders/float.rs @@ -3,13 +3,13 @@ use std::error::Error; // SENTINEL is used to terminate a float-encoded block. A sentinel marker value // is useful because blocks do not always end aligned to bytes, and spare empty // bits can otherwise have undesirable semantic meaning. -const SENTINEL: u64 = 0x7ff80000000000ff; // in the quiet NaN range. +const SENTINEL: u64 = 0x7ff8_0000_0000_00ff; // in the quiet NaN range. fn is_sentinel_f64(v: f64) -> bool { - return v.to_bits() == SENTINEL; + v.to_bits() == SENTINEL } fn is_sentinel_u64(v: u64) -> bool { - return v == SENTINEL; + v == SENTINEL } /// encode_all encodes a vector of floats into dst. @@ -19,9 +19,10 @@ fn is_sentinel_u64(v: u64) -> bool { /// two is determined. Leading and trailing zero bits are then analysed and /// representations based on those are stored. #[allow(dead_code)] +#[allow(clippy::many_single_char_names)] pub fn encode_all(src: &mut Vec, dst: &mut Vec) -> Result<(), Box> { dst.truncate(0); // reset buffer. - if src.len() == 0 { + if src.is_empty() { return Ok(()); } if dst.capacity() < 9 { @@ -40,7 +41,7 @@ pub fn encode_all(src: &mut Vec, dst: &mut Vec) -> Result<(), Box, dst: &mut Vec) -> Result<(), Box> 3; let vv_bytes = &vv.to_be_bytes(); - for i in k..k + 8 { - dst[i] = vv_bytes[i - k]; - } + dst[k..k + 8].clone_from_slice(&vv_bytes[0..(k + 8 - k)]); + n += (l - written) as usize; } else { prev_leading = leading; @@ -218,9 +218,7 @@ pub fn encode_all(src: &mut Vec, dst: &mut Vec) -> Result<(), Box> 3; let vv_bytes = &vv.to_be_bytes(); - for i in k..k + 8 { - dst[i] = vv_bytes[i - k]; - } + dst[k..k + 8].clone_from_slice(&vv_bytes[0..(k + 8 - k)]); n += l - written; } prev = cur; @@ -249,74 +247,75 @@ pub fn encode_all(src: &mut Vec, dst: &mut Vec) -> Result<(), Box) -> Result<(), Box> { if src.len() < 9 { return Ok(()); @@ -373,7 +372,7 @@ pub fn decode_all(src: &[u8], dst: &mut Vec) -> Result<(), Box> let mut meaningful_n = 64u8; loop { - if br_valid_bits <= 0 { + if br_valid_bits == 0 { match refill_cache(i) { Ok(res) => { br_cached_val = res.0; @@ -387,12 +386,12 @@ pub fn decode_all(src: &[u8], dst: &mut Vec) -> Result<(), Box> // read control bit 0. br_valid_bits -= 1; br_cached_val = br_cached_val.rotate_left(1); - if br_cached_val & 1 <= 0 { + if br_cached_val & 1 == 0 { dst.push(f64::from_bits(val)); continue; } - if br_valid_bits <= 0 { + if br_valid_bits == 0 { match refill_cache(i) { Ok(res) => { br_cached_val = res.0; @@ -433,7 +432,7 @@ pub fn decode_all(src: &[u8], dst: &mut Vec) -> Result<(), Box> br_cached_val = br_cached_val.rotate_left(bits_01 as u32); br_valid_bits -= bits_01; - lm_bits = lm_bits & !BIT_MASK[(bits_01 & 0x3f) as usize]; + lm_bits &= !BIT_MASK[(bits_01 & 0x3f) as usize]; lm_bits |= br_cached_val & BIT_MASK[(bits_01 & 0x3f) as usize]; } @@ -472,7 +471,7 @@ pub fn decode_all(src: &[u8], dst: &mut Vec) -> Result<(), Box> br_cached_val = br_cached_val.rotate_left(m_bits as u32); br_valid_bits = br_valid_bits.wrapping_sub(m_bits); - s_bits = s_bits & !BIT_MASK[(m_bits & 0x3f) as usize]; + s_bits &= !BIT_MASK[(m_bits & 0x3f) as usize]; s_bits |= br_cached_val & BIT_MASK[(m_bits & 0x3f) as usize]; } s_bits &= BIT_MASK[(meaningful_n & 0x3f) as usize]; diff --git a/src/encoders/integer.rs b/src/encoders/integer.rs index 885f7bb5f1..929e29c68a 100644 --- a/src/encoders/integer.rs +++ b/src/encoders/integer.rs @@ -18,7 +18,7 @@ enum Encoding { #[allow(dead_code)] pub fn encode_all<'a>(src: &mut Vec, dst: &'a mut Vec) -> Result<(), Box> { dst.truncate(0); // reset buffer. - if src.len() == 0 { + if src.is_empty() { return Ok(()); } @@ -88,7 +88,7 @@ fn zig_zag_decode(v: u64) -> i64 { // TODO(edd): this is expensive as it copies. There are cheap // but unsafe alternatives to look into such as std::mem::transmute fn i64_to_u64_vector(src: &[i64]) -> Vec { - src.into_iter().map(|x| *x as u64).collect::>() + src.iter().map(|x| *x as u64).collect::>() } // encode_rle encodes the value v, delta and count into dst. @@ -117,22 +117,22 @@ fn encode_rle(v: u64, delta: u64, count: u64, dst: &mut Vec) { /// decode_all decodes a slice of bytes into a vector of signed integers. #[allow(dead_code)] pub fn decode_all<'a>(src: &[u8], dst: &'a mut Vec) -> Result<(), Box> { - if src.len() == 0 { + if src.is_empty() { return Ok(()); } let encoding = &src[0] >> 4; match encoding { encoding if encoding == Encoding::Uncompressed as u8 => { - return decode_uncompressed(&src[1..], dst); // first byte not used + decode_uncompressed(&src[1..], dst) // first byte not used } - encoding if encoding == Encoding::Rle as u8 => return decode_rle(&src[1..], dst), - encoding if encoding == Encoding::Simple8b as u8 => return decode_simple8b(&src[1..], dst), - _ => return Err(From::from("invalid block encoding")), + encoding if encoding == Encoding::Rle as u8 => decode_rle(&src[1..], dst), + encoding if encoding == Encoding::Simple8b as u8 => decode_simple8b(&src[1..], dst), + _ => Err(From::from("invalid block encoding")), } } fn decode_uncompressed(src: &[u8], dst: &mut Vec) -> Result<(), Box> { - if src.len() == 0 || src.len() & 0x7 != 0 { + if src.is_empty() || src.len() & 0x7 != 0 { return Err(From::from("invalid uncompressed block length")); } @@ -161,13 +161,13 @@ fn decode_rle(src: &[u8], dst: &mut Vec) -> Result<(), Box> { let mut i = 8; // Skip first value let (delta, n) = u64::decode_var(&src[i..]); - if n <= 0 { + if n == 0 { return Err(From::from("unable to decode delta")); } i += n; let (count, n) = usize::decode_var(&src[i..]); - if n <= 0 { + if n == 0 { return Err(From::from("unable to decode count")); } diff --git a/src/encoders/simple8b.rs b/src/encoders/simple8b.rs index 7ae4a0d893..78a9424808 100644 --- a/src/encoders/simple8b.rs +++ b/src/encoders/simple8b.rs @@ -184,7 +184,7 @@ pub fn decode(v: u64, dst: &mut [u64]) -> usize { 5 } 12 => { - dst[0] = (v >> 0) & 0x7fff; + dst[0] = v & 0x7fff; dst[1] = (v >> 15) & 0x7fff; dst[2] = (v >> 30) & 0x7fff; dst[3] = (v >> 45) & 0x7fff; diff --git a/src/encoders/timestamp.rs b/src/encoders/timestamp.rs index b97df7e9c5..67298c2cb0 100644 --- a/src/encoders/timestamp.rs +++ b/src/encoders/timestamp.rs @@ -19,7 +19,7 @@ enum Encoding { #[allow(dead_code)] pub fn encode_all<'a>(src: &mut Vec, dst: &'a mut Vec) -> Result<(), Box> { dst.truncate(0); // reset buffer. - if src.len() == 0 { + if src.is_empty() { return Ok(()); } @@ -93,7 +93,7 @@ pub fn encode_all<'a>(src: &mut Vec, dst: &'a mut Vec) -> Result<(), Bo // TODO(edd): this is expensive as it copies. There are cheap // but unsafe alternatives to look into such as std::mem::transmute fn i64_to_u64_vector(src: &[i64]) -> Vec { - src.into_iter().map(|x| *x as u64).collect::>() + src.iter().map(|x| *x as u64).collect::>() } // encode_rle encodes the value v, delta and count into dst. @@ -146,23 +146,23 @@ fn encode_rle(v: u64, delta: u64, count: u64, dst: &mut Vec) { /// vector of signed integers. #[allow(dead_code)] pub fn decode_all<'a>(src: &[u8], dst: &'a mut Vec) -> Result<(), Box> { - if src.len() == 0 { + if src.is_empty() { return Ok(()); } let encoding = &src[0] >> 4; match encoding { encoding if encoding == Encoding::Uncompressed as u8 => { - return decode_uncompressed(&src[1..], dst); // first byte not used + decode_uncompressed(&src[1..], dst) // first byte not used } - encoding if encoding == Encoding::Rle as u8 => return decode_rle(&src, dst), - encoding if encoding == Encoding::Simple8b as u8 => return decode_simple8b(&src, dst), - _ => return Err(From::from("invalid block encoding")), + encoding if encoding == Encoding::Rle as u8 => decode_rle(&src, dst), + encoding if encoding == Encoding::Simple8b as u8 => decode_simple8b(&src, dst), + _ => Err(From::from("invalid block encoding")), } } // decode_uncompressed writes the binary encoded values in src into dst. fn decode_uncompressed(src: &[u8], dst: &mut Vec) -> Result<(), Box> { - if src.len() == 0 || src.len() & 0x7 != 0 { + if src.is_empty() || src.len() & 0x7 != 0 { return Err(From::from("invalid uncompressed block length")); } @@ -190,7 +190,7 @@ fn decode_rle(src: &[u8], dst: &mut Vec) -> Result<(), Box> { } // calculate the scaler from the lower 4 bits of the first byte. - let scaler = 10_u64.pow((src[0] & 0b00001111) as u32); + let scaler = 10_u64.pow((src[0] & 0b0000_1111) as u32); let mut i = 1; // TODO(edd): this should be possible to do in-place without copy. @@ -198,14 +198,14 @@ fn decode_rle(src: &[u8], dst: &mut Vec) -> Result<(), Box> { a.copy_from_slice(&src[i..i + 8]); i += 8; let (mut delta, n) = u64::decode_var(&src[i..]); - if n <= 0 { + if n == 0 { return Err(From::from("unable to decode delta")); } i += n; delta *= scaler; let (count, n) = usize::decode_var(&src[i..]); - if n <= 0 { + if n == 0 { return Err(From::from("unable to decode count")); } @@ -226,7 +226,7 @@ fn decode_simple8b(src: &[u8], dst: &mut Vec) -> Result<(), Box> return Err(From::from("not enough data to decode packed timestamp")); } - let scaler = 10_u64.pow((src[0] & 0b00001111) as u32); + let scaler = 10_u64.pow((src[0] & 0b0000_1111) as u32); // TODO(edd): pre-allocate res by counting bytes in encoded slice? let mut res = vec![]; From 92baa3d7e8f26ef6e5eb4af1ea7251b7ebd92b14 Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Fri, 14 Feb 2020 17:13:20 +0000 Subject: [PATCH 2/5] refactor: apply clippy --- src/storage/memdb.rs | 52 ++++++++----------- src/storage/rocksdb.rs | 101 +++++++++++++++--------------------- src/storage/series_store.rs | 2 +- 3 files changed, 63 insertions(+), 92 deletions(-) diff --git a/src/storage/memdb.rs b/src/storage/memdb.rs index b3bc8c2df5..db8287a6ca 100644 --- a/src/storage/memdb.rs +++ b/src/storage/memdb.rs @@ -15,6 +15,7 @@ use croaring::Treemap; // TODO: return errors if trying to insert data out of order in an individual series +#[derive(Default)] pub struct MemDB { default_ring_buffer_size: usize, bucket_id_to_series_data: Arc>>>, @@ -67,7 +68,7 @@ impl StoreInSeriesData for Point { } impl SeriesData { - fn write_points(&mut self, points: &Vec) { + fn write_points(&mut self, points: &[PointType]) { for p in points { p.write(self); } @@ -145,9 +146,7 @@ impl SeriesRingBuffer { fn oldest_time_and_position(&self) -> (i64, usize) { let mut pos = self.next_position; - if self.next_position == self.data.len() { - pos = 0; - } else if self.data[pos].time == std::i64::MAX { + if self.next_position == self.data.len() || self.data[pos].time == std::i64::MAX { pos = 0; } @@ -200,11 +199,11 @@ impl SeriesMap { let posting_list = self .posting_list .entry(list_key) - .or_insert(Treemap::create()); + .or_insert_with(Treemap::create); posting_list.add(self.last_id); // insert the tag key value mapping - let tag_values = self.tag_keys.entry(pair.key).or_insert(BTreeMap::new()); + let tag_values = self.tag_keys.entry(pair.key).or_insert_with(BTreeMap::new); tag_values.insert(pair.value, true); } @@ -307,13 +306,7 @@ impl MemDB { ) -> Result>, StorageError> { match self.bucket_id_to_series_map.read().unwrap().get(&bucket_id) { Some(map) => { - let keys: Vec = map - .read() - .unwrap() - .tag_keys - .keys() - .map(|k| k.clone()) - .collect(); + let keys: Vec = map.read().unwrap().tag_keys.keys().cloned().collect(); Ok(Box::new(keys.into_iter())) } None => Err(StorageError { @@ -331,7 +324,7 @@ impl MemDB { match self.bucket_id_to_series_map.read().unwrap().get(&bucket_id) { Some(map) => match map.read().unwrap().tag_keys.get(tag_key) { Some(values) => { - let values: Vec = values.keys().map(|v| v.clone()).collect(); + let values: Vec = values.keys().cloned().collect(); Ok(Box::new(values.into_iter())) } None => Ok(Box::new(vec![].into_iter())), @@ -394,7 +387,7 @@ impl MemDB { fn write_points_with_series_ids( &self, bucket_id: u32, - points: &Vec, + points: &[PointType], ) -> Result<(), StorageError> { let bucket_data = self.bucket_id_to_series_data.read().unwrap(); @@ -438,7 +431,7 @@ impl MemDB { }; let data = data.lock().unwrap(); - let buff = match FromSeries::from_series(&data, &series_id) { + let buff = match FromSeries::from_series(&data, series_id) { Some(b) => b, None => { return Err(StorageError { @@ -456,19 +449,18 @@ impl MemDB { } trait FromSeries: Clone { - fn from_series<'a>(data: &'a SeriesData, series_id: &u64) - -> Option<&'a SeriesRingBuffer>; + fn from_series<'a>(data: &'a SeriesData, series_id: u64) -> Option<&'a SeriesRingBuffer>; } impl FromSeries for i64 { - fn from_series<'a>(data: &'a SeriesData, series_id: &u64) -> Option<&'a SeriesRingBuffer> { - data.i64_series.get(series_id) + fn from_series<'a>(data: &'a SeriesData, series_id: u64) -> Option<&'a SeriesRingBuffer> { + data.i64_series.get(&series_id) } } impl FromSeries for f64 { - fn from_series<'a>(data: &'a SeriesData, series_id: &u64) -> Option<&'a SeriesRingBuffer> { - data.f64_series.get(series_id) + fn from_series<'a>(data: &'a SeriesData, series_id: u64) -> Option<&'a SeriesRingBuffer> { + data.f64_series.get(&series_id) } } @@ -488,7 +480,7 @@ impl Iterator for PointsIterator { let remaining = values.split_off(self.batch_size); - if remaining.len() != 0 { + if !remaining.is_empty() { self.values = Some(remaining); } @@ -575,12 +567,10 @@ fn evaluate_comparison( }; match op { - Comparison::Equal => return Ok(series_map.posting_list_for_key_value(&left, &right)), - comp => { - return Err(StorageError { - description: format!("unable to handle comparison {:?}", comp), - }) - } + Comparison::Equal => Ok(series_map.posting_list_for_key_value(&left, &right)), + comp => Err(StorageError { + description: format!("unable to handle comparison {:?}", comp), + }), } } @@ -623,9 +613,9 @@ impl SeriesStore for MemDB { fn write_points_with_series_ids( &self, bucket_id: u32, - points: &Vec, + points: &[PointType], ) -> Result<(), StorageError> { - self.write_points_with_series_ids(bucket_id, points) + self.write_points_with_series_ids(bucket_id, &points.to_vec()) } fn read_i64_range( diff --git a/src/storage/rocksdb.rs b/src/storage/rocksdb.rs index db3eb2f4c3..8b805ddd2f 100644 --- a/src/storage/rocksdb.rs +++ b/src/storage/rocksdb.rs @@ -57,7 +57,7 @@ impl RocksDB { Ok(names) => names .into_iter() .map(|name| { - if &name == BUCKET_CF { + if name == BUCKET_CF { bucket_cf_descriptor() } else { ColumnFamilyDescriptor::new(&name, index_cf_options()) @@ -87,11 +87,7 @@ impl RocksDB { /// # Arguments /// * bucket_id - the globally unique bucket id /// * points - individual values with their timestamps, series keys, and series IDs - pub fn write_points( - &self, - bucket_id: u32, - points: &Vec, - ) -> Result<(), StorageError> { + pub fn write_points(&self, bucket_id: u32, points: &[PointType]) -> Result<(), StorageError> { // TODO: validate bucket exists? let mut batch = WriteBatch::default(); @@ -399,14 +395,10 @@ impl RocksDB { }; match op { - Comparison::Equal => { - return self.get_posting_list_for_tag_key_value(bucket_id, &left, &right); - } - comp => { - return Err(StorageError { - description: format!("unable to handle comparison {:?}", comp), - }) - } + Comparison::Equal => self.get_posting_list_for_tag_key_value(bucket_id, &left, &right), + comp => Err(StorageError { + description: format!("unable to handle comparison {:?}", comp), + }), } } @@ -447,25 +439,22 @@ impl RocksDB { let db = self.db.read().unwrap(); - match db.cf_handle(&cf_name) { - Some(index) => { - let prefix = index_tag_key_prefix(bucket_id); - let mode = IteratorMode::From(&prefix, Direction::Forward); - let iter = db - .iterator_cf(index, mode) - .expect("unexpected rocksdb error getting iterator for index"); + if let Some(index) = db.cf_handle(&cf_name) { + let prefix = index_tag_key_prefix(bucket_id); + let mode = IteratorMode::From(&prefix, Direction::Forward); + let iter = db + .iterator_cf(index, mode) + .expect("unexpected rocksdb error getting iterator for index"); - for (key, _) in iter { - if !key.starts_with(&prefix) { - break; - } - - let k = std::str::from_utf8(&key[prefix.len()..]).unwrap(); // TODO: determine what we want to do with errors - keys.push(k.to_string()); + for (key, _) in iter { + if !key.starts_with(&prefix) { + break; } + + let k = std::str::from_utf8(&key[prefix.len()..]).unwrap(); // TODO: determine what we want to do with errors + keys.push(k.to_string()); } - None => (), - } + }; keys } @@ -481,24 +470,21 @@ impl RocksDB { let db = self.db.read().unwrap(); let mut values = vec![]; - match db.cf_handle(&cf_name) { - Some(index) => { - let prefix = index_tag_key_value_prefix(bucket_id, tag); - let mode = IteratorMode::From(&prefix, Direction::Forward); - let iter = db - .iterator_cf(index, mode) - .expect("unexpected rocksdb error getting iterator for index"); + if let Some(index) = db.cf_handle(&cf_name) { + let prefix = index_tag_key_value_prefix(bucket_id, tag); + let mode = IteratorMode::From(&prefix, Direction::Forward); + let iter = db + .iterator_cf(index, mode) + .expect("unexpected rocksdb error getting iterator for index"); - for (key, _) in iter { - if !key.starts_with(&prefix) { - break; - } - - let v = std::str::from_utf8(&key[prefix.len()..]).unwrap(); // TODO: determine what to do with errors - values.push(v.to_string()); + for (key, _) in iter { + if !key.starts_with(&prefix) { + break; } + + let v = std::str::from_utf8(&key[prefix.len()..]).unwrap(); // TODO: determine what to do with errors + values.push(v.to_string()); } - None => (), } values @@ -518,7 +504,7 @@ impl RocksDB { let mut map = self.series_insert_lock.write().expect("mutex poisoned"); // now only insert the new mutex if someone else hasn't done it between dropping read and obtaining write - if let None = map.get(&bucket_id) { + if map.get(&bucket_id).is_none() { map.insert(bucket_id, Mutex::new(1)); } } @@ -540,10 +526,7 @@ impl RocksDB { // create the column family to store the index if it doesn't exist let cf_name = index_cf_name(bucket_id); - let index_exists = match self.db.read().unwrap().cf_handle(&cf_name) { - Some(_) => true, - None => false, - }; + let index_exists = self.db.read().unwrap().cf_handle(&cf_name).is_some(); if !index_exists { self.db @@ -565,7 +548,7 @@ impl RocksDB { // now loop through the series and insert the index entries into the map for point in points { // don't bother with series in the collection that already have IDs - if let Some(_) = point.series_id() { + if point.series_id().is_some() { continue; } @@ -705,17 +688,15 @@ impl RocksDB { BucketEntryType::NextSeriesID => { // read the bucket id from the key let mut c = Cursor::new(&key[1..]); - let bucket_id = c.read_u32::().expect(&format!( - "couldn't read the bucket id from the key {:?}", - key - )); + let bucket_id = c.read_u32::().unwrap_or_else(|_| { + panic!("couldn't read the bucket id from the key {:?}", key) + }); // and the next series ID let mut c = Cursor::new(value); - let next_id = c.read_u64::().expect(&format!( - "couldn't read the next series id for bucket {}", - bucket_id - )); + let next_id = c.read_u64::().unwrap_or_else(|_| { + panic!("couldn't read the next series id for bucket {}", bucket_id) + }); id_mutex_map.insert(bucket_id, Mutex::new(next_id)); } BucketEntryType::Bucket => { @@ -804,7 +785,7 @@ impl SeriesStore for RocksDB { fn write_points_with_series_ids( &self, bucket_id: u32, - points: &Vec, + points: &[PointType], ) -> Result<(), StorageError> { self.write_points(bucket_id, &points) } diff --git a/src/storage/series_store.rs b/src/storage/series_store.rs index 32321f2941..663c3c70bc 100644 --- a/src/storage/series_store.rs +++ b/src/storage/series_store.rs @@ -5,7 +5,7 @@ pub trait SeriesStore: Sync + Send { fn write_points_with_series_ids( &self, bucket_id: u32, - points: &Vec, + points: &[PointType], ) -> Result<(), StorageError>; fn read_i64_range( From 1ad21b3e9013dacf4cf499c9dced0661b2d6b4dc Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Fri, 14 Feb 2020 17:13:25 +0000 Subject: [PATCH 3/5] refactor: apply clippy --- src/encoders/float.rs | 1 + src/line_parser/mod.rs | 25 ++++++++++--------------- src/main.rs | 2 +- src/time.rs | 5 +---- 4 files changed, 13 insertions(+), 20 deletions(-) diff --git a/src/encoders/float.rs b/src/encoders/float.rs index ec2b39e708..834ebe1fab 100644 --- a/src/encoders/float.rs +++ b/src/encoders/float.rs @@ -316,6 +316,7 @@ const BIT_MASK: [u64; 64] = [ /// decode_all decodes a slice of bytes into a vector of floats. #[allow(dead_code)] #[allow(clippy::many_single_char_names)] +#[allow(clippy::useless_let_if_seq)] pub fn decode_all(src: &[u8], dst: &mut Vec) -> Result<(), Box> { if src.len() < 9 { return Ok(()); diff --git a/src/line_parser/mod.rs b/src/line_parser/mod.rs index 730c56a09f..bcc54a9d71 100644 --- a/src/line_parser/mod.rs +++ b/src/line_parser/mod.rs @@ -104,13 +104,13 @@ impl PointType { /// cases where this series is already in the database, this parse step can be skipped entirely. /// The measurement is represented as a _m key and field as _f. pub fn index_pairs(key: &str) -> Result, ParseError> { - let mut chars = key.chars(); + let chars = key.chars(); let mut pairs = vec![]; let mut key = "_m".to_string(); let mut value = String::with_capacity(250); let mut reading_key = false; - while let Some(ch) = chars.next() { + for ch in chars { match ch { ',' => { reading_key = true; @@ -175,12 +175,10 @@ impl ResponseError for ParseError { pub fn parse(input: &str) -> Vec { let mut points: Vec = Vec::with_capacity(10000); let lines = input.lines(); - for line in lines { read_line(line, &mut points) } - - return points; + points } fn read_line(line: &str, points: &mut Vec) { @@ -237,22 +235,19 @@ fn read_value( ) -> bool { let mut value = String::new(); - while let Some(ch) = chars.next() { + for ch in chars { match ch { ' ' | ',' => { let series = measurement_tags.to_string() + "\t" + &field_name; // if the last character of the value is an i then it's an integer, otherwise it's // a float (at least until we support the other data types - let point = match value.ends_with("i") { - true => { - let val = value[..value.len() - 1].parse::().unwrap(); - PointType::new_i64(series, val, 0) - } - false => { - let val = value.parse::().unwrap(); - PointType::new_f64(series, val, 0) - } + let point = if value.ends_with('i') { + let val = value[..value.len() - 1].parse::().unwrap(); + PointType::new_i64(series, val, 0) + } else { + let val = value.parse::().unwrap(); + PointType::new_f64(series, val, 0) }; points.push(point); diff --git a/src/main.rs b/src/main.rs index 034dec731b..f434d31ab4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,7 +78,7 @@ async fn write( .json(serde_json::json!({ "error": format!("{}", err) }))); } - Ok(HttpResponse::Ok().json({})) + Ok(HttpResponse::Ok().json(())) } #[derive(Deserialize, Debug)] diff --git a/src/time.rs b/src/time.rs index 8a7a18afdf..99e3ab4ea1 100644 --- a/src/time.rs +++ b/src/time.rs @@ -41,10 +41,7 @@ pub fn parse_duration(s: &str) -> Result { } let i; - let mut start = 0; - if s.starts_with("-") { - start = 1; - } + let start = if s.starts_with('-') { 1 } else { 0 }; match s[start..].chars().position(|c| !c.is_digit(10)) { Some(p) => i = p + start, From 0b3c412cfc2bda9c89529067aae06bd2b8f74e9f Mon Sep 17 00:00:00 2001 From: Edd Robinson Date: Fri, 14 Feb 2020 18:27:53 +0000 Subject: [PATCH 4/5] chore: make clippy required CI step --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 3fbfce2b39..c531c11d52 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -58,7 +58,7 @@ jobs: - install_clang - run: name: Clippy - command: cargo clippy --all -j9 || echo "clippy failed, but ignoring this for now..." + command: cargo clippy --all -j9 test: docker: - image: circleci/rust:latest From bbbbf8ee07fd5097b464369115b42a942223e12b Mon Sep 17 00:00:00 2001 From: "Carol (Nichols || Goulding)" Date: Mon, 17 Feb 2020 08:10:53 -0500 Subject: [PATCH 5/5] fix: Remove unnecessary allocation --- src/storage/memdb.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage/memdb.rs b/src/storage/memdb.rs index db8287a6ca..9b05f0f92c 100644 --- a/src/storage/memdb.rs +++ b/src/storage/memdb.rs @@ -615,7 +615,7 @@ impl SeriesStore for MemDB { bucket_id: u32, points: &[PointType], ) -> Result<(), StorageError> { - self.write_points_with_series_ids(bucket_id, &points.to_vec()) + self.write_points_with_series_ids(bucket_id, points) } fn read_i64_range(