diff options
| author | Florian Hartwig <florian.j.hartwig@gmail.com> | 2016-10-11 19:22:41 +0200 |
|---|---|---|
| committer | Florian Hartwig <florian.j.hartwig@gmail.com> | 2016-10-11 19:45:09 +0200 |
| commit | 63ee8d0bbc9911ee121ed4af4f7e81cbd600d8b1 (patch) | |
| tree | e6365a213c907e9b9c4aa9ebf8089fb5e3cf0667 /src/libcollections | |
| parent | e33562078ff6027c116cb43abd052e256354ab2f (diff) | |
| download | rust-63ee8d0bbc9911ee121ed4af4f7e81cbd600d8b1.tar.gz rust-63ee8d0bbc9911ee121ed4af4f7e81cbd600d8b1.zip | |
Specialize Vec::extend to Vec::extend_from_slice
Diffstat (limited to 'src/libcollections')
| -rw-r--r-- | src/libcollections/vec.rs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 54fd19dbe30..4a727adb797 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1571,7 +1571,24 @@ impl<T> Vec<T> { #[stable(feature = "extend_ref", since = "1.2.0")] impl<'a, T: 'a + Copy> Extend<&'a T> for Vec<T> { fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) { - self.extend(iter.into_iter().cloned()); + <I as SpecExtendVec<T>>::extend_vec(iter, self); + } +} + +// helper trait for specialization of Vec's Extend impl +trait SpecExtendVec<T> { + fn extend_vec(self, vec: &mut Vec<T>); +} + +impl <'a, T: 'a + Copy, I: IntoIterator<Item=&'a T>> SpecExtendVec<T> for I { + default fn extend_vec(self, vec: &mut Vec<T>) { + vec.extend(self.into_iter().cloned()); + } +} + +impl<'a, T: Copy> SpecExtendVec<T> for &'a [T] { + fn extend_vec(self, vec: &mut Vec<T>) { + vec.extend_from_slice(self); } } |
