Skip to content

Commit

Permalink
Address some clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
declanvk committed Sep 15, 2024
1 parent 35f1ede commit 944f55c
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 34 deletions.
2 changes: 1 addition & 1 deletion benches/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn dense_fixed_length_key_tree() -> &'static TreeMap<[u8; 2], usize> {
pub fn with_prefixes_tree() -> &'static TreeMap<Box<[u8]>, usize> {
static TREE: OnceLock<TreeMap<Box<[u8]>, usize>> = OnceLock::new();

&TREE.get_or_init(|| {
TREE.get_or_init(|| {
tree_from_keys(generate_key_with_prefix(
[7; 5],
[
Expand Down
6 changes: 3 additions & 3 deletions benches/iai_callgrind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn bench_lookup_single<'a, K: AsBytes, V, const PREFIX_LEN: usize>(
tree: &'a TreeMap<K, V, PREFIX_LEN>,
key: &K,
) -> &'a V {
tree.get(&key).unwrap()
tree.get(key).unwrap()
}

#[library_benchmark]
Expand Down Expand Up @@ -81,7 +81,7 @@ fn insert_single_setup<K: AsBytes + Clone, V: Clone, const PREFIX_LEN: usize>(
key: &K,
) -> (TreeMap<K, V, PREFIX_LEN>, K) {
let mut tree = tree.clone();
let _ = tree.remove(&key);
let _ = tree.remove(key);
(tree, key.clone())
}

Expand All @@ -102,7 +102,7 @@ fn insert_multiple_setup<K: AsBytes + Clone, V: Clone, const PREFIX_LEN: usize>(
let mut tree = tree.clone();
let mut output = Vec::with_capacity(keys.len());
for key in keys {
let _ = tree.remove(&key);
let _ = tree.remove(key);
output.push(key.clone());
}
(tree, output)
Expand Down
2 changes: 1 addition & 1 deletion benches/node/match_prefix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn bench(c: &mut Criterion) {
node256_large.write_child(99, leaf_opaque);

{
let mut old_group = c.benchmark_group(format!("match_prefix"));
let mut old_group = c.benchmark_group("match_prefix");
old_group.bench_function("node48/small/match", |b| {
b.iter(|| std::hint::black_box(node48_small.match_prefix(key_small_match, 0)));
});
Expand Down
16 changes: 8 additions & 8 deletions benches/node/min_max.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,29 @@ fn bench(c: &mut Criterion) {
.collect();

for (idx, node) in nodes48.clone() {
let mut group = c.benchmark_group(format!("min/n48"));
group.bench_function(format!("{idx}").as_str(), |b| {
let mut group = c.benchmark_group("min/n48");
group.bench_function(idx.to_string(), |b| {
b.iter(|| std::hint::black_box(node.min()));
});
}

for (idx, node) in nodes48.clone() {
let mut group = c.benchmark_group(format!("max/n48"));
group.bench_function(format!("{idx}").as_str(), |b| {
let mut group = c.benchmark_group("max/n48");
group.bench_function(idx.to_string(), |b| {
b.iter(|| std::hint::black_box(node.max()));
});
}

for (idx, node) in nodes256.clone() {
let mut group = c.benchmark_group(format!("min/n256"));
group.bench_function(format!("{idx}").as_str(), |b| {
let mut group = c.benchmark_group("min/n256");
group.bench_function(idx.to_string(), |b| {
b.iter(|| std::hint::black_box(node.min()));
});
}

for (idx, node) in nodes256.clone() {
let mut group = c.benchmark_group(format!("max/n256"));
group.bench_function(format!("{idx}").as_str(), |b| {
let mut group = c.benchmark_group("max/n256");
group.bench_function(idx.to_string(), |b| {
b.iter(|| std::hint::black_box(node.max()));
});
}
Expand Down
10 changes: 3 additions & 7 deletions benches/tree/dict_insert.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::CString, time::Duration};
use std::ffi::CString;

use blart::TreeMap;
use criterion::{criterion_group, Criterion};
Expand Down Expand Up @@ -45,10 +45,8 @@ fn bench(c: &mut Criterion) {
let part_bytes: usize = part_words.iter().map(|w| w.as_bytes_with_nul().len()).sum();

{
let mut group = c.benchmark_group(format!("dict/words/full"));
let mut group = c.benchmark_group("dict/words/full");
group.throughput(criterion::Throughput::Bytes(bytes as u64));
group.warm_up_time(Duration::from_secs(10));
group.measurement_time(Duration::from_secs(30));
group.bench_function("insert/asc", |b| {
b.iter_batched(|| words.clone(), insert, criterion::BatchSize::SmallInput)
});
Expand All @@ -68,10 +66,8 @@ fn bench(c: &mut Criterion) {
});
}
{
let mut group = c.benchmark_group(format!("dict/words/part"));
let mut group = c.benchmark_group("dict/words/part");
group.throughput(criterion::Throughput::Bytes(part_bytes as u64));
group.warm_up_time(Duration::from_secs(10));
group.measurement_time(Duration::from_secs(30));
group.bench_function("insert/asc", |b| {
b.iter_batched(
|| part_words.clone(),
Expand Down
4 changes: 2 additions & 2 deletions benches/tree/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn bench(c: &mut Criterion) {
.collect();

{
let mut group = c.benchmark_group(format!("entry"));
let mut group = c.benchmark_group("entry");

for (ty, vals) in [("vacant", vacant.clone()), ("occupied", occupied.clone())] {
group.bench_function(format!("{ty}/or_default"), |b| {
Expand Down Expand Up @@ -103,7 +103,7 @@ fn bench(c: &mut Criterion) {
}

{
let mut group = c.benchmark_group(format!("entry/default"));
let mut group = c.benchmark_group("entry/default");

for (ty, vals) in [("vacant", vacant), ("occupied", occupied)] {
group.bench_function(format!("{ty}/or_default"), |b| {
Expand Down
12 changes: 4 additions & 8 deletions benches/tree/generated_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use blart::{
};
use criterion::{criterion_group, Criterion, Throughput};

fn gen_group(c: &mut Criterion, group: String, keys: Vec<Box<[u8]>>) {
fn gen_group(c: &mut Criterion, group: &str, keys: Vec<Box<[u8]>>) {
let mut group = c.benchmark_group(group);
group.warm_up_time(std::time::Duration::from_secs(5));
group.measurement_time(std::time::Duration::from_secs(15));
Expand Down Expand Up @@ -45,13 +45,9 @@ fn bench(c: &mut Criterion) {
)
.collect();

gen_group(c, format!("generated_insert/skewed"), skewed);
gen_group(c, format!("generated_insert/fixed_length"), fixed_length);
gen_group(
c,
format!("generated_insert/large_prefixes"),
large_prefixes,
);
gen_group(c, "generated_insert/skewed", skewed);
gen_group(c, "generated_insert/fixed_length", fixed_length);
gen_group(c, "generated_insert/large_prefixes", large_prefixes);
}

criterion_group!(bench_generated_insert_group, bench);
2 changes: 1 addition & 1 deletion benches/tree/iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn bench(c: &mut Criterion) {
.map(|s| (CString::new(s).unwrap(), 0usize))
.collect();

let mut group = c.benchmark_group(format!("iter/tree"));
let mut group = c.benchmark_group("iter/tree");

group.bench_function("dict/forward", |b| {
b.iter(|| {
Expand Down
6 changes: 4 additions & 2 deletions src/bytes/mapped.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,8 +444,10 @@ impl_ordered_bytes_ints_arrays!(
);

/// This struct represents a conversion of **IP addresses** (V4 and V6) into
/// their component bytes. The ordering of IP addresses is already the
/// lexicographic ordering of the component bytes, so it will be preserved.
/// their component bytes.
///
/// The ordering of IP addresses is already the lexicographic ordering of the
/// component bytes, so it will be preserved.
pub struct ToOctets;

impl BytesMapping<Ipv4Addr> for ToOctets {
Expand Down
2 changes: 1 addition & 1 deletion src/tests_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ pub fn generate_key_fixed_length<const KEY_LENGTH: usize>(
return Some(next_value);
}

let mut new_next_value = next_value.clone();
let mut new_next_value = next_value;
for idx in (0..new_next_value.len()).rev() {
if new_next_value[idx] == self.level_widths[idx] {
new_next_value[idx] = u8::MIN;
Expand Down

0 comments on commit 944f55c

Please sign in to comment.