From a150dcc872b4f003c4a0e4cd7bb0e7c51ec791b2 Mon Sep 17 00:00:00 2001 From: Thom Chiovoloni Date: Mon, 6 Jul 2020 07:43:32 -0700 Subject: [PATCH] Remove pointless `black_box` call, add a comment about the `unaligned_` benches, and clean up stray semicolon --- src/libcore/benches/ascii.rs | 2 +- src/libcore/benches/ascii/is_ascii.rs | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/libcore/benches/ascii.rs b/src/libcore/benches/ascii.rs index 6a4d706cff6..05dd7adff1f 100644 --- a/src/libcore/benches/ascii.rs +++ b/src/libcore/benches/ascii.rs @@ -60,7 +60,7 @@ macro_rules! benches { } )+ } - }; + } } use test::black_box; diff --git a/src/libcore/benches/ascii/is_ascii.rs b/src/libcore/benches/ascii/is_ascii.rs index 45ba2f8fe82..729b0a04eb6 100644 --- a/src/libcore/benches/ascii/is_ascii.rs +++ b/src/libcore/benches/ascii/is_ascii.rs @@ -7,7 +7,9 @@ macro_rules! benches { benches!(mod short SHORT[..] $($name $arg $body)+); benches!(mod medium MEDIUM[..] $($name $arg $body)+); benches!(mod long LONG[..] $($name $arg $body)+); - + // Ensure we benchmark cases where the functions are called with strings + // that are not perfectly aligned or have a length which is not a + // multiple of size_of::() (or both) benches!(mod unaligned_head MEDIUM[1..] $($name $arg $body)+); benches!(mod unaligned_tail MEDIUM[..(MEDIUM.len() - 1)] $($name $arg $body)+); benches!(mod unaligned_both MEDIUM[1..(MEDIUM.len() - 1)] $($name $arg $body)+); @@ -22,8 +24,7 @@ macro_rules! benches { bencher.bytes = $input[$range].len() as u64; let mut vec = $input.as_bytes().to_vec(); bencher.iter(|| { - black_box(&mut vec); - let $arg = black_box(&vec[$range]); + let $arg: &[u8] = &black_box(&mut vec)[$range]; black_box($body) }) }