Skip to content

Commit

Permalink
Merge pull request #71 from lnicola/array-iter
Browse files Browse the repository at this point in the history
Use `slice::iter` instead of `into_iter` to avoid future breakage
  • Loading branch information
darrenldl committed Oct 31, 2019
2 parents 7aa1ff9 + 103fa2b commit 3b44858
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fn main () {

// Make a copy and transform it into option shards arrangement
// for feeding into reconstruct_shards
let mut shards: Vec<_> = master_copy.clone().into_iter().map(Some).collect();
let mut shards: Vec<_> = master_copy.iter().cloned().map(Some).collect();

// We can remove up to 2 shards, which may be data or parity shards
shards[0] = None;
Expand Down
4 changes: 2 additions & 2 deletions src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ impl<F: Field> ReedSolomon<F> {
// matrix could be used to generate the shards that we have
// from the original data.
let mut sub_matrix = Matrix::new(self.data_shard_count, self.data_shard_count);
for (sub_matrix_row, &valid_index) in valid_indices.into_iter().enumerate() {
for (sub_matrix_row, &valid_index) in valid_indices.iter().enumerate() {
for c in 0..self.data_shard_count {
sub_matrix.set(sub_matrix_row, c, self.matrix.get(valid_index, c));
}
Expand Down Expand Up @@ -791,7 +791,7 @@ impl<F: Field> ReedSolomon<F> {
let mut invalid_indices: SmallVec<[usize; 32]> = SmallVec::with_capacity(data_shard_count);

// Separate the shards into groups
for (matrix_row, shard) in shards.into_iter().enumerate() {
for (matrix_row, shard) in shards.iter_mut().enumerate() {
// get or initialize the shard so we can reconstruct in-place,
// but if we are only reconstructing data shard,
// do not initialize if the shard is not a data shard
Expand Down
2 changes: 1 addition & 1 deletion src/galois_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ mod tests {
#[test]
fn test_slice_add() {
let length_list = [16, 32, 34];
for len in length_list.into_iter() {
for len in length_list.iter() {
let mut input = vec![0; *len];
fill_random(&mut input);
let mut output = vec![0; *len];
Expand Down
4 changes: 2 additions & 2 deletions src/matrix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ macro_rules! acc {

pub fn flatten<T>(m: Vec<Vec<T>>) -> Vec<T> {
let mut result: Vec<T> = Vec::with_capacity(m.len() * m[0].len());
for row in m.into_iter() {
for v in row.into_iter() {
for row in m {
for v in row {
result.push(v);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn shards_to_option_shards<T: Clone>(shards: &[Vec<T>]) -> Vec<Option<Vec<T>>> {
fn shards_into_option_shards<T>(shards: Vec<Vec<T>>) -> Vec<Option<Vec<T>>> {
let mut result = Vec::with_capacity(shards.len());

for v in shards.into_iter() {
for v in shards {
result.push(Some(v));
}
result
Expand All @@ -79,7 +79,7 @@ fn option_shards_to_shards<T: Clone>(shards: &[Option<Vec<T>>]) -> Vec<Vec<T>> {
fn option_shards_into_shards<T>(shards: Vec<Option<Vec<T>>>) -> Vec<Vec<T>> {
let mut result = Vec::with_capacity(shards.len());

for shard in shards.into_iter() {
for shard in shards {
let shard = match shard {
Some(x) => x,
None => panic!("Missing shard"),
Expand Down

0 comments on commit 3b44858

Please sign in to comment.