diff --git a/plonky2/src/hash/hash_types.rs b/plonky2/src/hash/hash_types.rs index ed6fca43..8187979b 100644 --- a/plonky2/src/hash/hash_types.rs +++ b/plonky2/src/hash/hash_types.rs @@ -31,14 +31,12 @@ impl HashOut { } } - pub fn from_partial(mut elements: Vec) -> Self { - debug_assert!(elements.len() <= 4); - while elements.len() < 4 { - elements.push(F::ZERO); - } - Self { - elements: [elements[0], elements[1], elements[2], elements[3]], - } + pub fn from_partial(elements_in: &[F]) -> Self { + debug_assert!(elements_in.len() <= 4); + + let mut elements = [F::ZERO; 4]; + elements[0..elements_in.len()].copy_from_slice(elements_in); + Self { elements } } pub fn rand_from_rng(rng: &mut R) -> Self { diff --git a/plonky2/src/hash/hashing.rs b/plonky2/src/hash/hashing.rs index ea205654..eb238e51 100644 --- a/plonky2/src/hash/hashing.rs +++ b/plonky2/src/hash/hashing.rs @@ -14,11 +14,11 @@ pub const SPONGE_WIDTH: usize = SPONGE_RATE + SPONGE_CAPACITY; /// Hash the vector if necessary to reduce its length to ~256 bits. If it already fits, this is a /// no-op. -pub fn hash_or_noop>(inputs: Vec) -> HashOut { +pub fn hash_or_noop>(inputs: &[F]) -> HashOut { if inputs.len() <= 4 { HashOut::from_partial(inputs) } else { - hash_n_to_hash_no_pad::(&inputs) + hash_n_to_hash_no_pad::(inputs) } }