diff --git a/benches/compression.rs b/benches/compression.rs index 531b64e85..88059be5a 100644 --- a/benches/compression.rs +++ b/benches/compression.rs @@ -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)] @@ -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()) } } @@ -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)] @@ -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()) } } diff --git a/benches/token_router.rs b/benches/token_router.rs index 51dd0effd..12f66525d 100644 --- a/benches/token_router.rs +++ b/benches/token_router.rs @@ -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)); }) } diff --git a/src/filters/capture.rs b/src/filters/capture.rs index de1066668..5123b47a2 100644 --- a/src/filters/capture.rs +++ b/src/filters/capture.rs @@ -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 _); } @@ -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); } @@ -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 _); @@ -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); } diff --git a/src/filters/capture/affix.rs b/src/filters/capture/affix.rs index cff9dad80..c26e685e9 100644 --- a/src/filters/capture/affix.rs +++ b/src/filters/capture/affix.rs @@ -41,7 +41,7 @@ impl super::CaptureStrategy for Prefix { ( value, if self.remove { - self.size as isize * -1 + -(self.size as isize) } else { 0 }, diff --git a/src/filters/debug.rs b/src/filters/debug.rs index 920f4c29b..4c12977b6 100644 --- a/src/filters/debug.rs +++ b/src/filters/debug.rs @@ -39,7 +39,7 @@ impl Debug { impl Filter for Debug { #[cfg_attr(feature = "instrument", tracing::instrument(skip(self, ctx)))] fn read(&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(()) } @@ -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(()) }