From 18d5b10b989ada05e245f29cb23cd2284e496cdb Mon Sep 17 00:00:00 2001 From: Alin Dima Date: Wed, 6 Dec 2023 15:52:38 +0200 Subject: [PATCH] implement #24 for simd code path (#30) --- reed-solomon-novelpoly/src/field/inc_encode.rs | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/reed-solomon-novelpoly/src/field/inc_encode.rs b/reed-solomon-novelpoly/src/field/inc_encode.rs index b934854..b09989e 100644 --- a/reed-solomon-novelpoly/src/field/inc_encode.rs +++ b/reed-solomon-novelpoly/src/field/inc_encode.rs @@ -243,21 +243,17 @@ pub fn encode_sub_faster8(bytes: &[u8], n: usize, k: usize) -> Result= bytes_len); - // tuple_windows are only used here + // tuples are only used here use itertools::Itertools; // pad the incoming bytes with trailing 0s // so we get a buffer of size `N` in `GF` symbols let zero_bytes_to_add = n * 2 - bytes_len; - let elm_data = Vec::::from_iter( - bytes - .iter() - .copied() - .chain(std::iter::repeat(0u8).take(zero_bytes_to_add)) - .tuple_windows() - .step_by(2) - .map(|(a,b)| Additive(Elt::from_be_bytes([a, b]))) - ); + let mut elm_data = Vec::with_capacity(n); + let zeros = std::iter::repeat(&0u8).take(zero_bytes_to_add); + for (first, second) in bytes.iter().chain(zeros).tuples() { + elm_data.push(Additive(Elt::from_be_bytes([*first, *second]))); + } // update new data bytes with zero padded bytes // `l` is now `GF(2^16)` symbols