Skip to content

Commit

Permalink
Fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
Jake-Shadle committed Dec 20, 2024
1 parent e71897f commit 6237602
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 31 deletions.
26 changes: 8 additions & 18 deletions benches/compression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,11 @@ mod decompress {
let compressor = Compressor::from(Mode::Snappy);

b.with_inputs(|| {
let mut packet = pool.clone().alloc_slice(&packet);
compressor.encode(pool.clone(), &mut packet).unwrap();
packet
let packet = pool.clone().alloc_slice(&packet);
compressor.encode(&packet).unwrap()
})
.input_counter(|buf| divan::counter::BytesCount::new(buf.len()))
.bench_local_refs(|buf| {
compressor.decode(pool.clone(), buf).unwrap();
})
.bench_local_refs(|buf| compressor.decode(buf).unwrap())
}

#[divan::bench(consts = PACKET_SIZES)]
Expand All @@ -52,14 +49,11 @@ mod decompress {
let compressor = Compressor::from(Mode::Lz4);

b.with_inputs(|| {
let mut packet = pool.clone().alloc_slice(&packet);
compressor.encode(pool.clone(), &mut packet).unwrap();
packet
let packet = pool.clone().alloc_slice(&packet);
compressor.encode(&packet).unwrap()
})
.input_counter(|buf| divan::counter::BytesCount::new(buf.len()))
.bench_local_refs(|buf| {
compressor.decode(pool.clone(), buf).unwrap();
})
.bench_local_refs(|buf| compressor.decode(buf).unwrap())
}
}

Expand All @@ -75,9 +69,7 @@ mod compress {

b.with_inputs(|| pool.clone().alloc_slice(&packet))
.input_counter(|buf| divan::counter::BytesCount::new(buf.len()))
.bench_local_refs(|buf| {
compressor.encode(pool.clone(), buf).unwrap();
})
.bench_local_refs(|buf| compressor.encode(buf).unwrap())
}

#[divan::bench(consts = PACKET_SIZES)]
Expand All @@ -88,8 +80,6 @@ mod compress {

b.with_inputs(|| pool.clone().alloc_slice(&packet))
.input_counter(|buf| divan::counter::BytesCount::new(buf.len()))
.bench_local_refs(|buf| {
compressor.encode(pool.clone(), buf).unwrap();
})
.bench_local_refs(|buf| compressor.encode(buf).unwrap())
}
}
5 changes: 3 additions & 2 deletions benches/token_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ fn token_router(b: Bencher, token_kind: &str) {
.counter(divan::counter::BytesCount::new(total_token_size))
.bench_local_values(|(cm, buffer, mut dest, metadata)| {
let mut rc = quilkin::filters::ReadContext {
endpoints: cm,
endpoints: &cm,
destinations: &mut dest,
source: quilkin::net::EndpointAddress::LOCALHOST,
contents: buffer,
metadata,
};

let _ = divan::black_box(filter.sync_read(&mut rc));
use quilkin::filters::Filter;
let _ = divan::black_box(filter.read(&mut rc));
})
}

Expand Down
16 changes: 8 additions & 8 deletions src/filters/capture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Filter for Capture {

if remove != 0 {
if remove < 0 {
ctx.contents.remove_head(remove.abs() as _);
ctx.contents.remove_head(remove.unsigned_abs());
} else {
ctx.contents.remove_tail(remove as _);
}
Expand Down Expand Up @@ -198,8 +198,8 @@ mod tests {
let end = Regex {
pattern: ::regex::bytes::Regex::new(".{3}$").unwrap(),
};
let mut contents = alloc_buffer(b"helloabc");
let result = end.capture(&mut contents).unwrap().0;
let contents = alloc_buffer(b"helloabc");
let result = end.capture(&contents).unwrap().0;
assert_eq!(Value::Bytes(b"abc".to_vec().into()), result);
assert_eq!(b"helloabc", &*contents);
}
Expand All @@ -211,14 +211,14 @@ mod tests {
remove: false,
};
let mut contents = alloc_buffer(b"helloabc");
let (result, remove) = end.capture(&mut contents).unwrap();
let (result, remove) = end.capture(&contents).unwrap();
assert_eq!(Value::Bytes(b"abc".to_vec().into()), result);
assert_eq!(remove, 0);
assert_eq!(b"helloabc", &*contents);

end.remove = true;

let (result, remove) = end.capture(&mut contents).unwrap();
let (result, remove) = end.capture(&contents).unwrap();
assert_eq!(Value::Bytes(b"abc".to_vec().into()), result);
assert_eq!(remove, 3);
contents.remove_tail(remove as _);
Expand All @@ -233,17 +233,17 @@ mod tests {
};
let mut contents = alloc_buffer(b"abchello");

let (result, remove) = beg.capture(&mut contents).unwrap();
let (result, remove) = beg.capture(&contents).unwrap();
assert_eq!(Value::Bytes(b"abc".to_vec().into()), result);
assert_eq!(remove, 0);
assert_eq!(b"abchello", &*contents);

beg.remove = true;

let (result, remove) = beg.capture(&mut contents).unwrap();
let (result, remove) = beg.capture(&contents).unwrap();
assert_eq!(Value::Bytes(b"abc".to_vec().into()), result);
assert_eq!(remove, -3);
contents.remove_head(remove.abs() as _);
contents.remove_head(remove.unsigned_abs());
assert_eq!(b"hello", &*contents);
}

Expand Down
2 changes: 1 addition & 1 deletion src/filters/capture/affix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl super::CaptureStrategy for Prefix {
(
value,
if self.remove {
self.size as isize * -1
-(self.size as isize)
} else {
0
},
Expand Down
4 changes: 2 additions & 2 deletions src/filters/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl Debug {
impl Filter for Debug {
#[cfg_attr(feature = "instrument", tracing::instrument(skip(self, ctx)))]
fn read<P: Packet>(&self, ctx: &mut ReadContext<'_, P>) -> Result<(), FilterError> {
info!(id = ?self.config.id, source = ?&ctx.source, contents = ?String::from_utf8_lossy(&ctx.contents.as_slice()), "Read filter event");
info!(id = ?self.config.id, source = ?&ctx.source, contents = ?String::from_utf8_lossy(ctx.contents.as_slice()), "Read filter event");
Ok(())
}

Expand All @@ -49,7 +49,7 @@ impl Filter for Debug {
id = ?self.config.id,
source = ?&ctx.source,
dest = ?&ctx.dest,
contents = ?String::from_utf8_lossy(&ctx.contents.as_slice()), "Write filter event"
contents = ?String::from_utf8_lossy(ctx.contents.as_slice()), "Write filter event"
);
Ok(())
}
Expand Down

0 comments on commit 6237602

Please sign in to comment.