Skip to content

Commit

Permalink
Add Debug and Clone to general purpose Engine
Browse files Browse the repository at this point in the history
  • Loading branch information
marshallpierce committed Oct 21, 2023
1 parent 53a8737 commit cc06367
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
9 changes: 3 additions & 6 deletions benches/benchmarks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ fn do_decode_bench_slice(b: &mut Bencher, &size: &usize) {
fill(&mut v);
let encoded = STANDARD.encode(&v);

let mut buf = Vec::new();
buf.resize(size, 0);
let mut buf = vec![0; size];
b.iter(|| {
STANDARD.decode_slice(&encoded, &mut buf).unwrap();
black_box(&buf);
Expand All @@ -52,8 +51,7 @@ fn do_decode_bench_stream(b: &mut Bencher, &size: &usize) {
fill(&mut v);
let encoded = STANDARD.encode(&v);

let mut buf = Vec::new();
buf.resize(size, 0);
let mut buf = vec![0; size];
buf.truncate(0);

b.iter(|| {
Expand Down Expand Up @@ -96,9 +94,8 @@ fn do_encode_bench_reuse_buf(b: &mut Bencher, &size: &usize) {
fn do_encode_bench_slice(b: &mut Bencher, &size: &usize) {
let mut v: Vec<u8> = Vec::with_capacity(size);
fill(&mut v);
let mut buf = Vec::new();
// conservative estimate of encoded size
buf.resize(v.len() * 2, 0);
let mut buf = vec![0; v.len() * 2];
b.iter(|| STANDARD.encode_slice(&v, &mut buf).unwrap());
}

Expand Down
2 changes: 2 additions & 0 deletions src/engine/general_purpose/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pub(crate) const INVALID_VALUE: u8 = 255;
/// - It uses no vector CPU instructions, so it will work on any system.
/// - It is reasonably fast (~2-3GiB/s).
/// - It is not constant-time, though, so it is vulnerable to timing side-channel attacks. For loading cryptographic keys, etc, it is suggested to use the forthcoming constant-time implementation.
#[derive(Debug, Clone)]
pub struct GeneralPurpose {
encode_table: [u8; 64],
decode_table: [u8; 256],
Expand Down
2 changes: 1 addition & 1 deletion src/read/decoder_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn trailing_junk() {
saw_error = true;
break;
}
Ok(read) if read == 0 => break,
Ok(0) => break,
Ok(_) => (),
}
}
Expand Down

0 comments on commit cc06367

Please sign in to comment.