style: Warn on unnecessary use of iter and fix all cases

This is more idiomatic than calling `iter` explicitly.
pull/24376/head
Carol (Nichols || Goulding) 2020-02-17 18:23:31 -05:00
parent c7a7dde51f
commit cb62590582
4 changed files with 7 additions and 6 deletions

View File

@ -57,7 +57,7 @@ pub fn encode_all<'a>(src: &mut Vec<i64>, dst: &'a mut Vec<u8>) -> Result<(), Bo
dst.reserve_exact(cap - dst.capacity());
}
dst.push((Encoding::Uncompressed as u8) << 4);
for delta in deltas.iter() {
for delta in &deltas {
dst.extend_from_slice(&delta.to_be_bytes());
}
return Ok(());
@ -201,7 +201,7 @@ fn decode_simple8b(src: &[u8], dst: &mut Vec<i64>) -> Result<(), Box<dyn Error>>
simple8b::decode_all(&src[8..], &mut res);
// TODO(edd): fix this. It's copying, which is slowwwwwwwww.
let mut next = dst[0];
for v in res.iter() {
for v in &res {
next += zig_zag_decode(*v);
dst.push(next);
}

View File

@ -57,7 +57,7 @@ pub fn encode_all<'a>(src: &mut Vec<i64>, dst: &'a mut Vec<u8>) -> Result<(), Bo
}
dst.push((Encoding::Uncompressed as u8) << 4);
for delta in deltas.iter() {
for delta in &deltas {
dst.extend_from_slice(&delta.to_be_bytes());
}
return Ok(());
@ -238,7 +238,7 @@ fn decode_simple8b(src: &[u8], dst: &mut Vec<i64>) -> Result<(), Box<dyn Error>>
let mut next = dst[dst.len() - 1];
if scaler > 1 {
// TODO(edd): fix this. It's copying, which is slowwwwwwwww.
for v in res.iter() {
for v in &res {
next += (v * scaler) as i64;
dst.push(next);
}
@ -246,7 +246,7 @@ fn decode_simple8b(src: &[u8], dst: &mut Vec<i64>) -> Result<(), Box<dyn Error>>
}
// TODO(edd): fix this. It's copying, which is slowwwwwwwww.
for v in res.iter() {
for v in &res {
next += *v as i64;
dst.push(next);
}

View File

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

View File

@ -638,7 +638,7 @@ impl RocksDB {
}
// do the index writes from the in temporary in memory map
for (k, v) in index_map.iter() {
for (k, v) in &index_map {
let _ = batch.put_cf(index_cf, k, v.serialize().unwrap());
}