More clippy passes on all targets (cargo clippy --all-targets --all-features -- -D warnings -A clippy::match-ref-pats -A clippy::needless-lifetimes)

Signed-off-by: Victor Porof <victor.porof@gmail.com>
without.crypto
Victor Porof 5 years ago
parent bca20c45c4
commit 2970b17c71
  1. 8
      benches/cursor.rs
  2. 8
      benches/transaction.rs
  3. 2
      benches/utils.rs
  4. 14
      src/cursor.rs

@ -35,20 +35,18 @@ fn bench_get_seq_iter(b: &mut Bencher) {
for (key, data) in cursor.iter().map(Result::unwrap) {
i = i + key.len() + data.len();
count = count + 1;
count += 1;
}
for (key, data) in cursor.iter().filter_map(Result::ok) {
i = i + key.len() + data.len();
count = count + 1;
count += 1;
}
fn iterate<'a>(cursor: &mut RoCursor) -> Result<()> {
fn iterate(cursor: &mut RoCursor) -> Result<()> {
let mut i = 0;
let mut count = 0u32;
for result in cursor.iter() {
let (key, data) = result?;
i = i + key.len() + data.len();
count = count + 1;
}
Ok(())
}

@ -32,13 +32,13 @@ fn bench_get_rand(b: &mut Bencher) {
let db = env.open_db(None).unwrap();
let txn = env.begin_ro_txn().unwrap();
let mut keys: Vec<String> = (0..n).map(|n| get_key(n)).collect();
let mut keys: Vec<String> = (0..n).map(get_key).collect();
XorShiftRng::new_unseeded().shuffle(&mut keys[..]);
b.iter(|| {
let mut i = 0usize;
for key in &keys {
i = i + txn.get(db, key).unwrap().len();
i += txn.get(db, key).unwrap().len();
}
black_box(i);
});
@ -51,7 +51,7 @@ fn bench_get_rand_raw(b: &mut Bencher) {
let db = env.open_db(None).unwrap();
let _txn = env.begin_ro_txn().unwrap();
let mut keys: Vec<String> = (0..n).map(|n| get_key(n)).collect();
let mut keys: Vec<String> = (0..n).map(get_key).collect();
XorShiftRng::new_unseeded().shuffle(&mut keys[..]);
let dbi = db.dbi();
@ -74,7 +74,7 @@ fn bench_get_rand_raw(b: &mut Bencher) {
mdb_get(txn, dbi, &mut key_val, &mut data_val);
i = i + key_val.mv_size;
i += key_val.mv_size;
}
black_box(i);
});

@ -16,7 +16,7 @@ pub fn get_data(n: u32) -> String {
format!("data{}", n)
}
pub fn setup_bench_db<'a>(num_rows: u32) -> (TempDir, Environment) {
pub fn setup_bench_db(num_rows: u32) -> (TempDir, Environment) {
let dir = TempDir::new("test").unwrap();
let env = Environment::new().open(dir.path()).unwrap();

@ -614,34 +614,34 @@ mod test {
let txn = env.begin_ro_txn().unwrap();
let mut cursor = txn.open_ro_cursor(db).unwrap();
assert_eq!(items, cursor.iter_dup().flat_map(|x| x).collect::<Result<Vec<_>>>().unwrap());
assert_eq!(items, cursor.iter_dup().flatten().collect::<Result<Vec<_>>>().unwrap());
cursor.get(Some(b"b"), None, MDB_SET).unwrap();
assert_eq!(
items.clone().into_iter().skip(4).collect::<Vec<(&[u8], &[u8])>>(),
cursor.iter_dup().flat_map(|x| x).collect::<Result<Vec<_>>>().unwrap()
cursor.iter_dup().flatten().collect::<Result<Vec<_>>>().unwrap()
);
assert_eq!(items, cursor.iter_dup_start().flat_map(|x| x).collect::<Result<Vec<(&[u8], &[u8])>>>().unwrap());
assert_eq!(items, cursor.iter_dup_start().flatten().collect::<Result<Vec<(&[u8], &[u8])>>>().unwrap());
assert_eq!(
items.clone().into_iter().skip(3).collect::<Vec<(&[u8], &[u8])>>(),
cursor.iter_dup_from(b"b").flat_map(|x| x).collect::<Result<Vec<_>>>().unwrap()
cursor.iter_dup_from(b"b").flatten().collect::<Result<Vec<_>>>().unwrap()
);
assert_eq!(
items.clone().into_iter().skip(3).collect::<Vec<(&[u8], &[u8])>>(),
cursor.iter_dup_from(b"ab").flat_map(|x| x).collect::<Result<Vec<_>>>().unwrap()
cursor.iter_dup_from(b"ab").flatten().collect::<Result<Vec<_>>>().unwrap()
);
assert_eq!(
items.clone().into_iter().skip(9).collect::<Vec<(&[u8], &[u8])>>(),
cursor.iter_dup_from(b"d").flat_map(|x| x).collect::<Result<Vec<_>>>().unwrap()
cursor.iter_dup_from(b"d").flatten().collect::<Result<Vec<_>>>().unwrap()
);
assert_eq!(
vec!().into_iter().collect::<Vec<(&[u8], &[u8])>>(),
cursor.iter_dup_from(b"f").flat_map(|x| x).collect::<Result<Vec<_>>>().unwrap()
cursor.iter_dup_from(b"f").flatten().collect::<Result<Vec<_>>>().unwrap()
);
assert_eq!(

Loading…
Cancel
Save