Skip to content

Commit

Permalink
Implement Clone::clone_from for LinkedList
Browse files Browse the repository at this point in the history
  • Loading branch information
crgl committed Oct 1, 2019
1 parent 702b45e commit 7b480cd
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/liballoc/collections/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1197,6 +1197,19 @@ impl<T: Clone> Clone for LinkedList<T> {
fn clone(&self) -> Self {
self.iter().cloned().collect()
}

fn clone_from(&mut self, other: &Self) {
let mut iter_other = other.iter();
if self.len() > other.len() {
self.split_off(other.len());
}
for elem in self.iter_mut() {
elem.clone_from(iter_other.next().unwrap());
}
if !iter_other.is_empty() {
self.extend(iter_other.cloned());
}
}
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand Down

0 comments on commit 7b480cd

Please sign in to comment.