vec: Remove the Vec specialization for .extend()

This now produces as good code (with optimizations) using the TrustedLen
codepath.
This commit is contained in:
Ulrik Sverdrup 2016-10-27 00:40:09 +02:00
parent 2411be5cae
commit 5dc9db541e

View file

@ -76,7 +76,6 @@ use core::ptr;
use core::ptr::Shared;
use core::slice;
use super::SpecExtend;
use super::range::RangeArgument;
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector.'
@ -1554,22 +1553,10 @@ impl<'a, T> IntoIterator for &'a mut Vec<T> {
impl<T> Extend<T> for Vec<T> {
#[inline]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I) {
<Self as SpecExtend<I>>::spec_extend(self, iter);
}
}
impl<I: IntoIterator> SpecExtend<I> for Vec<I::Item> {
default fn spec_extend(&mut self, iter: I) {
self.extend_desugared(iter.into_iter())
}
}
impl<T> SpecExtend<Vec<T>> for Vec<T> {
fn spec_extend(&mut self, ref mut other: Vec<T>) {
self.append(other);
}
}
trait IsTrustedLen : Iterator {
fn trusted_len(&self) -> Option<usize> { None }
}