Skip to content

Commit c1b7250

Browse files
committed
REFAC Use clone_from_slice, extend in ArrayVec::clone_from
This is just a cleanup of the code, with less repetition.
1 parent 0872a59 commit c1b7250

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/lib.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -893,22 +893,16 @@ impl<A: Array> Clone for ArrayVec<A>
893893
fn clone_from(&mut self, rhs: &Self) {
894894
// recursive case for the common prefix
895895
let prefix = cmp::min(self.len(), rhs.len());
896-
{
897-
let a = &mut self[..prefix];
898-
let b = &rhs[..prefix];
899-
for i in 0..prefix {
900-
a[i].clone_from(&b[i]);
901-
}
902-
}
896+
self[..prefix].clone_from_slice(&rhs[..prefix]);
897+
903898
if prefix < self.len() {
904899
// rhs was shorter
905900
for _ in 0..self.len() - prefix {
906901
self.pop();
907902
}
908903
} else {
909-
for elt in &rhs[self.len()..] {
910-
self.push(elt.clone());
911-
}
904+
let rhs_elems = rhs[self.len()..].iter().cloned();
905+
self.extend(rhs_elems);
912906
}
913907
}
914908
}

0 commit comments

Comments
 (0)