mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Auto merge of #85754 - the8472:revert-83770, r=Mark-Simulacrum
Revert "Auto merge of #83770 - the8472:tra-extend, r=Mark-Simulacrum" Due to a performance regression that didn't show up in the original perf run this reverts commit9111b8ae97
(#83770), reversing changes made to9a700d2947
. Since since is expected to have the inverse impact it should probably be rollup=never. r? `@Mark-Simulacrum`
This commit is contained in:
commit
bff138dbd9
@ -1,5 +1,5 @@
|
||||
use crate::alloc::Allocator;
|
||||
use core::iter::{TrustedLen, TrustedRandomAccess};
|
||||
use core::iter::TrustedLen;
|
||||
use core::ptr::{self};
|
||||
use core::slice::{self};
|
||||
|
||||
@ -11,49 +11,6 @@ pub(super) trait SpecExtend<T, I> {
|
||||
}
|
||||
|
||||
impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
{
|
||||
default fn spec_extend(&mut self, iter: I) {
|
||||
SpecExtendInner::spec_extend(self, iter);
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, A: Allocator> SpecExtend<T, IntoIter<T>> for Vec<T, A> {
|
||||
fn spec_extend(&mut self, mut iterator: IntoIter<T>) {
|
||||
unsafe {
|
||||
self.append_elements(iterator.as_slice() as _);
|
||||
}
|
||||
iterator.ptr = iterator.end;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec<T, A>
|
||||
where
|
||||
I: Iterator<Item = &'a T>,
|
||||
T: Clone,
|
||||
{
|
||||
default fn spec_extend(&mut self, iterator: I) {
|
||||
SpecExtend::spec_extend(self, iterator.cloned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) {
|
||||
let slice = iterator.as_slice();
|
||||
unsafe { self.append_elements(slice) };
|
||||
}
|
||||
}
|
||||
|
||||
// Helper trait to disambiguate overlapping specializations
|
||||
trait SpecExtendInner<T, I> {
|
||||
fn spec_extend(&mut self, iter: I);
|
||||
}
|
||||
|
||||
impl<T, I, A: Allocator> SpecExtendInner<T, I> for Vec<T, A>
|
||||
where
|
||||
I: Iterator<Item = T>,
|
||||
{
|
||||
@ -62,7 +19,7 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, I, A: Allocator> SpecExtendInner<T, I> for Vec<T, A>
|
||||
impl<T, I, A: Allocator> SpecExtend<T, I> for Vec<T, A>
|
||||
where
|
||||
I: TrustedLen<Item = T>,
|
||||
{
|
||||
@ -98,22 +55,31 @@ where
|
||||
}
|
||||
}
|
||||
|
||||
impl<T, I, A: Allocator> SpecExtendInner<T, I> for Vec<T, A>
|
||||
where
|
||||
I: TrustedLen<Item = T> + TrustedRandomAccess,
|
||||
{
|
||||
default fn spec_extend(&mut self, mut iterator: I) {
|
||||
let size = iterator.size();
|
||||
self.reserve(size);
|
||||
|
||||
// SAFETY: reserve ensured that there is sufficient capacity for the additional items.
|
||||
// The loop upholds the TRA requirements by accessing each element only once.
|
||||
impl<T, A: Allocator> SpecExtend<T, IntoIter<T>> for Vec<T, A> {
|
||||
fn spec_extend(&mut self, mut iterator: IntoIter<T>) {
|
||||
unsafe {
|
||||
let sink = self.as_mut_ptr().add(self.len());
|
||||
for i in 0..size {
|
||||
ptr::write(sink.add(i), iterator.__iterator_get_unchecked(i));
|
||||
self.set_len(self.len() + 1);
|
||||
}
|
||||
self.append_elements(iterator.as_slice() as _);
|
||||
}
|
||||
iterator.ptr = iterator.end;
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, I, A: Allocator + 'a> SpecExtend<&'a T, I> for Vec<T, A>
|
||||
where
|
||||
I: Iterator<Item = &'a T>,
|
||||
T: Clone,
|
||||
{
|
||||
default fn spec_extend(&mut self, iterator: I) {
|
||||
self.spec_extend(iterator.cloned())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a, T: 'a, A: Allocator + 'a> SpecExtend<&'a T, slice::Iter<'a, T>> for Vec<T, A>
|
||||
where
|
||||
T: Copy,
|
||||
{
|
||||
fn spec_extend(&mut self, iterator: slice::Iter<'a, T>) {
|
||||
let slice = iterator.as_slice();
|
||||
unsafe { self.append_elements(slice) };
|
||||
}
|
||||
}
|
||||
|
@ -416,10 +416,6 @@ impl<A: Debug + TrustedRandomAccess, B: Debug + TrustedRandomAccess> ZipFmt<A, B
|
||||
|
||||
/// An iterator whose items are random-accessible efficiently
|
||||
///
|
||||
/// Iterators that implement this trait should also implement TrustedLen which
|
||||
/// allows specialization to disambiguate overlaps with a `TrustedLen + TrustedRandomAccess`
|
||||
/// bound.
|
||||
///
|
||||
/// # Safety
|
||||
///
|
||||
/// The iterator's `size_hint` must be exact and cheap to call.
|
||||
|
Loading…
Reference in New Issue
Block a user