Skip to content

Commit

Permalink
Refactor to use arrayvec 0.7
Browse files Browse the repository at this point in the history
In spite of the large diff, this is a fairly small actual change:
just use arrayvec 0.7 everywhere and instead of using the array
parameter, use <T, const N: usize> parameters.
  • Loading branch information
workingjubilee authored and oconnor663 committed Jul 25, 2021
1 parent 7bf791e commit 6336755
Show file tree
Hide file tree
Showing 14 changed files with 51 additions and 51 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ default = ["std"]
std = ["blake2b_simd/std", "blake2s_simd/std"]

[dependencies]
arrayvec = "0.5.0"
arrayvec = "0.7.0"
blake2b_simd = { path = "./blake2b", default-features = false }
blake2s_simd = { path = "./blake2s", default-features = false }
blake2-avx2-sneves = { path = "benches/blake2-avx2-sneves", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion benches/bench_multiprocess/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ openssl = "0.10.23"
libsodium-ffi = "0.1.17"
blake2-avx2-sneves = { path = "../blake2-avx2-sneves" }
page_size = "0.4.1"
arrayvec = "0.5.0"
arrayvec = "0.7.0"
6 changes: 3 additions & 3 deletions benches/bench_multiprocess/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ fn blake2s_hash() -> u128 {
// }
// let params = blake2b_simd::Params::new();
// bench(|| {
// let mut jobs = arrayvec::ArrayVec::<[_; blake2b_simd::many::MAX_DEGREE]>::new();
// let mut jobs = arrayvec::ArrayVec::<_, { blake2b_simd::many::MAX_DEGREE }>::new();
// for input in &mut inputs {
// let job = blake2b_simd::many::HashManyJob::new(&params, input.get());
// jobs.push(job);
Expand All @@ -129,7 +129,7 @@ fn blake2b_hash_many() -> u128 {
}
let params = blake2b_simd::Params::new();
bench(|| {
let mut jobs = arrayvec::ArrayVec::<[_; blake2b_simd::many::MAX_DEGREE]>::new();
let mut jobs = arrayvec::ArrayVec::<_, { blake2b_simd::many::MAX_DEGREE }>::new();
for input in &mut inputs {
let job = blake2b_simd::many::HashManyJob::new(&params, input.get());
jobs.push(job);
Expand All @@ -149,7 +149,7 @@ fn blake2s_hash_many() -> u128 {
}
let params = blake2s_simd::Params::new();
bench(|| {
let mut jobs = arrayvec::ArrayVec::<[_; blake2s_simd::many::MAX_DEGREE]>::new();
let mut jobs = arrayvec::ArrayVec::<_, { blake2s_simd::many::MAX_DEGREE }>::new();
for input in &mut inputs {
let job = blake2s_simd::many::HashManyJob::new(&params, input.get());
jobs.push(job);
Expand Down
2 changes: 1 addition & 1 deletion blake2b/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ uninline_portable = []

[dependencies]
arrayref = "0.3.5"
arrayvec = { version = "0.5.0", default-features = false }
arrayvec = { version = "0.7.0", default-features = false }
constant_time_eq = "0.1.3"
2 changes: 1 addition & 1 deletion blake2b/src/blake2bp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,7 +488,7 @@ pub(crate) mod test {
// support of the real implementation. We need this because the official test vectors don't
// include any inputs large enough to exercise all the branches in the buffering logic.
fn blake2bp_reference(input: &[u8]) -> Hash {
let mut leaves = arrayvec::ArrayVec::<[_; DEGREE]>::new();
let mut leaves = arrayvec::ArrayVec::<_, DEGREE>::new();
for leaf_index in 0..DEGREE {
leaves.push(
crate::Params::new()
Expand Down
16 changes: 8 additions & 8 deletions blake2b/src/guts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,13 +444,13 @@ mod test {

let mut input_buffer = [0; 100 * BLOCKBYTES];
paint_test_input(&mut input_buffer);
let mut inputs = ArrayVec::<[_; N]>::new();
let mut inputs = ArrayVec::<_, N>::new();
for i in 0..N {
inputs.push(&input_buffer[i..]);
}

exercise_cases(|stride, length, last_node, finalize, count| {
let mut reference_words = ArrayVec::<[_; N]>::new();
let mut reference_words = ArrayVec::<_, N>::new();
for i in 0..N {
let words = reference_compression(
&inputs[i][..length],
Expand All @@ -463,11 +463,11 @@ mod test {
reference_words.push(words);
}

let mut test_words = ArrayVec::<[_; N]>::new();
let mut test_words = ArrayVec::<_, N>::new();
for i in 0..N {
test_words.push(initial_test_words(i));
}
let mut jobs = ArrayVec::<[_; N]>::new();
let mut jobs = ArrayVec::<_, N>::new();
for (i, words) in test_words.iter_mut().enumerate() {
jobs.push(Job {
input: &inputs[i][..length],
Expand Down Expand Up @@ -509,13 +509,13 @@ mod test {

let mut input_buffer = [0; 100 * BLOCKBYTES];
paint_test_input(&mut input_buffer);
let mut inputs = ArrayVec::<[_; N]>::new();
let mut inputs = ArrayVec::<_, N>::new();
for i in 0..N {
inputs.push(&input_buffer[i..]);
}

exercise_cases(|stride, length, last_node, finalize, count| {
let mut reference_words = ArrayVec::<[_; N]>::new();
let mut reference_words = ArrayVec::<_, N>::new();
for i in 0..N {
let words = reference_compression(
&inputs[i][..length],
Expand All @@ -528,11 +528,11 @@ mod test {
reference_words.push(words);
}

let mut test_words = ArrayVec::<[_; N]>::new();
let mut test_words = ArrayVec::<_, N>::new();
for i in 0..N {
test_words.push(initial_test_words(i));
}
let mut jobs = ArrayVec::<[_; N]>::new();
let mut jobs = ArrayVec::<_, N>::new();
for (i, words) in test_words.iter_mut().enumerate() {
jobs.push(Job {
input: &inputs[i][..length],
Expand Down
4 changes: 2 additions & 2 deletions blake2b/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ impl Default for State {
}
}

type HexString = arrayvec::ArrayString<[u8; 2 * OUTBYTES]>;
type HexString = arrayvec::ArrayString<{ 2 * OUTBYTES }>;

/// A finalized BLAKE2 hash, with constant-time equality.
#[derive(Clone, Copy)]
Expand All @@ -600,7 +600,7 @@ impl Hash {
}

/// Convert the hash to a lowercase hexadecimal
/// [`ArrayString`](https://docs.rs/arrayvec/0.4/arrayvec/struct.ArrayString.html).
/// [`ArrayString`](https://docs.rs/arrayvec/0.7/arrayvec/struct.ArrayString.html).
pub fn to_hex(&self) -> HexString {
bytes_to_hex(self.as_bytes())
}
Expand Down
10 changes: 5 additions & 5 deletions blake2b/src/many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn degree() -> usize {
guts::Implementation::detect().degree()
}

type JobsVec<'a, 'b> = ArrayVec<[Job<'a, 'b>; guts::MAX_DEGREE]>;
type JobsVec<'a, 'b> = ArrayVec<Job<'a, 'b>, { guts::MAX_DEGREE }>;

#[inline(always)]
fn fill_jobs_vec<'a, 'b>(
Expand Down Expand Up @@ -453,7 +453,7 @@ mod test {
inputs[i] = &input[..chunks * BLOCKBYTES];
}

let mut params: ArrayVec<[Params; LEN]> = ArrayVec::new();
let mut params: ArrayVec<Params, LEN> = ArrayVec::new();
for i in 0..LEN {
let mut p = Params::new();
p.node_offset(i as u64);
Expand All @@ -464,7 +464,7 @@ mod test {
params.push(p);
}

let mut jobs: ArrayVec<[HashManyJob; LEN]> = ArrayVec::new();
let mut jobs: ArrayVec<HashManyJob, LEN> = ArrayVec::new();
for i in 0..LEN {
jobs.push(HashManyJob::new(&params[i], inputs[i]));
}
Expand Down Expand Up @@ -495,7 +495,7 @@ mod test {
inputs[i] = &input[..chunks * BLOCKBYTES];
}

let mut params: ArrayVec<[Params; LEN]> = ArrayVec::new();
let mut params: ArrayVec<Params, LEN> = ArrayVec::new();
for i in 0..LEN {
let mut p = Params::new();
p.node_offset(i as u64);
Expand All @@ -506,7 +506,7 @@ mod test {
params.push(p);
}

let mut states: ArrayVec<[State; LEN]> = ArrayVec::new();
let mut states: ArrayVec<State, LEN> = ArrayVec::new();
for i in 0..LEN {
states.push(params[i].to_state());
}
Expand Down
2 changes: 1 addition & 1 deletion blake2s/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ std = []

[dependencies]
arrayref = "0.3.5"
arrayvec = { version = "0.5.0", default-features = false }
arrayvec = { version = "0.7.0", default-features = false }
constant_time_eq = "0.1.3"
2 changes: 1 addition & 1 deletion blake2s/src/blake2sp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ pub(crate) mod test {
// support of the real implementation. We need this because the official test vectors don't
// include any inputs large enough to exercise all the branches in the buffering logic.
fn blake2sp_reference(input: &[u8]) -> Hash {
let mut leaves = arrayvec::ArrayVec::<[_; DEGREE]>::new();
let mut leaves = arrayvec::ArrayVec::<_, DEGREE>::new();
for leaf_index in 0..DEGREE {
leaves.push(
crate::Params::new()
Expand Down
16 changes: 8 additions & 8 deletions blake2s/src/guts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,13 +441,13 @@ mod test {

let mut input_buffer = [0; 100 * BLOCKBYTES];
paint_test_input(&mut input_buffer);
let mut inputs = ArrayVec::<[_; N]>::new();
let mut inputs = ArrayVec::<_, N>::new();
for i in 0..N {
inputs.push(&input_buffer[i..]);
}

exercise_cases(|stride, length, last_node, finalize, count| {
let mut reference_words = ArrayVec::<[_; N]>::new();
let mut reference_words = ArrayVec::<_, N>::new();
for i in 0..N {
let words = reference_compression(
&inputs[i][..length],
Expand All @@ -460,11 +460,11 @@ mod test {
reference_words.push(words);
}

let mut test_words = ArrayVec::<[_; N]>::new();
let mut test_words = ArrayVec::<_, N>::new();
for i in 0..N {
test_words.push(initial_test_words(i));
}
let mut jobs = ArrayVec::<[_; N]>::new();
let mut jobs = ArrayVec::<_, N>::new();
for (i, words) in test_words.iter_mut().enumerate() {
jobs.push(Job {
input: &inputs[i][..length],
Expand Down Expand Up @@ -506,13 +506,13 @@ mod test {

let mut input_buffer = [0; 100 * BLOCKBYTES];
paint_test_input(&mut input_buffer);
let mut inputs = ArrayVec::<[_; N]>::new();
let mut inputs = ArrayVec::<_, N>::new();
for i in 0..N {
inputs.push(&input_buffer[i..]);
}

exercise_cases(|stride, length, last_node, finalize, count| {
let mut reference_words = ArrayVec::<[_; N]>::new();
let mut reference_words = ArrayVec::<_, N>::new();
for i in 0..N {
let words = reference_compression(
&inputs[i][..length],
Expand All @@ -525,11 +525,11 @@ mod test {
reference_words.push(words);
}

let mut test_words = ArrayVec::<[_; N]>::new();
let mut test_words = ArrayVec::<_, N>::new();
for i in 0..N {
test_words.push(initial_test_words(i));
}
let mut jobs = ArrayVec::<[_; N]>::new();
let mut jobs = ArrayVec::<_, N>::new();
for (i, words) in test_words.iter_mut().enumerate() {
jobs.push(Job {
input: &inputs[i][..length],
Expand Down
4 changes: 2 additions & 2 deletions blake2s/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ impl Default for State {
}
}

type HexString = arrayvec::ArrayString<[u8; 2 * OUTBYTES]>;
type HexString = arrayvec::ArrayString<{ 2 * OUTBYTES }>;

/// A finalized BLAKE2 hash, with constant-time equality.
#[derive(Clone, Copy)]
Expand All @@ -592,7 +592,7 @@ impl Hash {
}

/// Convert the hash to a lowercase hexadecimal
/// [`ArrayString`](https://docs.rs/arrayvec/0.4/arrayvec/struct.ArrayString.html).
/// [`ArrayString`](https://docs.rs/arrayvec/0.7/arrayvec/struct.ArrayString.html).
pub fn to_hex(&self) -> HexString {
bytes_to_hex(self.as_bytes())
}
Expand Down
10 changes: 5 additions & 5 deletions blake2s/src/many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ pub fn degree() -> usize {
guts::Implementation::detect().degree()
}

type JobsVec<'a, 'b> = ArrayVec<[Job<'a, 'b>; guts::MAX_DEGREE]>;
type JobsVec<'a, 'b> = ArrayVec<Job<'a, 'b>, { guts::MAX_DEGREE }>;

#[inline(always)]
fn fill_jobs_vec<'a, 'b>(
Expand Down Expand Up @@ -453,7 +453,7 @@ mod test {
inputs[i] = &input[..chunks * BLOCKBYTES];
}

let mut params: ArrayVec<[Params; LEN]> = ArrayVec::new();
let mut params: ArrayVec<Params, LEN> = ArrayVec::new();
for i in 0..LEN {
let mut p = Params::new();
p.node_offset(i as u64);
Expand All @@ -464,7 +464,7 @@ mod test {
params.push(p);
}

let mut jobs: ArrayVec<[HashManyJob; LEN]> = ArrayVec::new();
let mut jobs: ArrayVec<HashManyJob, LEN> = ArrayVec::new();
for i in 0..LEN {
jobs.push(HashManyJob::new(&params[i], inputs[i]));
}
Expand Down Expand Up @@ -495,7 +495,7 @@ mod test {
inputs[i] = &input[..chunks * BLOCKBYTES];
}

let mut params: ArrayVec<[Params; LEN]> = ArrayVec::new();
let mut params: ArrayVec<Params, LEN> = ArrayVec::new();
for i in 0..LEN {
let mut p = Params::new();
p.node_offset(i as u64);
Expand All @@ -506,7 +506,7 @@ mod test {
params.push(p);
}

let mut states: ArrayVec<[State; LEN]> = ArrayVec::new();
let mut states: ArrayVec<State, LEN> = ArrayVec::new();
for i in 0..LEN {
states.push(params[i].to_state());
}
Expand Down
Loading

0 comments on commit 6336755

Please sign in to comment.