@@ -55,6 +55,10 @@ use self::spec_extend::SpecExtend;
5555
5656mod spec_extend;
5757
58+ use self :: spec_from_iter:: SpecFromIter ;
59+
60+ mod spec_from_iter;
61+
5862#[ cfg( test) ]
5963mod tests;
6064
@@ -586,6 +590,35 @@ impl<T, A: Allocator> VecDeque<T, A> {
586590 VecDeque { head : 0 , len : 0 , buf : RawVec :: with_capacity_in ( capacity, alloc) }
587591 }
588592
593+ /// For use by `vec::IntoIter::into_vecdeque`
594+ ///
595+ /// # Safety
596+ ///
597+ /// All the usual requirements on the allocated memory like in
598+ /// `Vec::from_raw_parts_in`, but takes a *range* of elements that are
599+ /// initialized rather than only supporting `0..len`. Requires that
600+ /// `initialized.start` ≤ `initialized.end` ≤ `capacity`.
601+ #[ inline]
602+ pub ( crate ) unsafe fn from_contiguous_raw_parts_in (
603+ ptr : * mut T ,
604+ initialized : Range < usize > ,
605+ capacity : usize ,
606+ alloc : A ,
607+ ) -> Self {
608+ debug_assert ! ( initialized. start <= initialized. end) ;
609+ debug_assert ! ( initialized. end <= capacity) ;
610+
611+ // SAFETY: Our safety precondition guarantees the range length won't wrap,
612+ // and that the allocation is valid for use in `RawVec`.
613+ unsafe {
614+ VecDeque {
615+ head : initialized. start ,
616+ len : initialized. end . unchecked_sub ( initialized. start ) ,
617+ buf : RawVec :: from_raw_parts_in ( ptr, capacity, alloc) ,
618+ }
619+ }
620+ }
621+
589622 /// Provides a reference to the element at the given index.
590623 ///
591624 /// Element at index 0 is the front of the queue.
@@ -2699,18 +2732,8 @@ impl<T, A: Allocator> IndexMut<usize> for VecDeque<T, A> {
26992732
27002733#[ stable( feature = "rust1" , since = "1.0.0" ) ]
27012734impl < T > FromIterator < T > for VecDeque < T > {
2702- #[ inline]
27032735 fn from_iter < I : IntoIterator < Item = T > > ( iter : I ) -> VecDeque < T > {
2704- // Since converting is O(1) now, might as well re-use that logic
2705- // (including things like the `vec::IntoIter`→`Vec` specialization)
2706- // especially as that could save us some monomorphiziation work
2707- // if one uses the same iterators (like slice ones) with both.
2708- return from_iter_via_vec ( iter. into_iter ( ) ) ;
2709-
2710- #[ inline]
2711- fn from_iter_via_vec < U > ( iter : impl Iterator < Item = U > ) -> VecDeque < U > {
2712- Vec :: from_iter ( iter) . into ( )
2713- }
2736+ SpecFromIter :: spec_from_iter ( iter. into_iter ( ) )
27142737 }
27152738}
27162739
0 commit comments