@@ -105,6 +105,10 @@ mod source_iter_marker;
105
105
106
106
mod partial_eq;
107
107
108
+ use self :: spec_from_elem:: SpecFromElem ;
109
+
110
+ mod spec_from_elem;
111
+
108
112
/// A contiguous growable array type, written `Vec<T>` but pronounced 'vector'.
109
113
///
110
114
/// # Examples
@@ -1995,61 +1999,6 @@ pub fn from_elem_in<T: Clone, A: Allocator>(elem: T, n: usize, alloc: A) -> Vec<
1995
1999
<T as SpecFromElem >:: from_elem ( elem, n, alloc)
1996
2000
}
1997
2001
1998
- // Specialization trait used for Vec::from_elem
1999
- trait SpecFromElem : Sized {
2000
- fn from_elem < A : Allocator > ( elem : Self , n : usize , alloc : A ) -> Vec < Self , A > ;
2001
- }
2002
-
2003
- impl < T : Clone > SpecFromElem for T {
2004
- default fn from_elem < A : Allocator > ( elem : Self , n : usize , alloc : A ) -> Vec < Self , A > {
2005
- let mut v = Vec :: with_capacity_in ( n, alloc) ;
2006
- v. extend_with ( n, ExtendElement ( elem) ) ;
2007
- v
2008
- }
2009
- }
2010
-
2011
- impl SpecFromElem for i8 {
2012
- #[ inline]
2013
- fn from_elem < A : Allocator > ( elem : i8 , n : usize , alloc : A ) -> Vec < i8 , A > {
2014
- if elem == 0 {
2015
- return Vec { buf : RawVec :: with_capacity_zeroed_in ( n, alloc) , len : n } ;
2016
- }
2017
- unsafe {
2018
- let mut v = Vec :: with_capacity_in ( n, alloc) ;
2019
- ptr:: write_bytes ( v. as_mut_ptr ( ) , elem as u8 , n) ;
2020
- v. set_len ( n) ;
2021
- v
2022
- }
2023
- }
2024
- }
2025
-
2026
- impl SpecFromElem for u8 {
2027
- #[ inline]
2028
- fn from_elem < A : Allocator > ( elem : u8 , n : usize , alloc : A ) -> Vec < u8 , A > {
2029
- if elem == 0 {
2030
- return Vec { buf : RawVec :: with_capacity_zeroed_in ( n, alloc) , len : n } ;
2031
- }
2032
- unsafe {
2033
- let mut v = Vec :: with_capacity_in ( n, alloc) ;
2034
- ptr:: write_bytes ( v. as_mut_ptr ( ) , elem, n) ;
2035
- v. set_len ( n) ;
2036
- v
2037
- }
2038
- }
2039
- }
2040
-
2041
- impl < T : Clone + IsZero > SpecFromElem for T {
2042
- #[ inline]
2043
- fn from_elem < A : Allocator > ( elem : T , n : usize , alloc : A ) -> Vec < T , A > {
2044
- if elem. is_zero ( ) {
2045
- return Vec { buf : RawVec :: with_capacity_zeroed_in ( n, alloc) , len : n } ;
2046
- }
2047
- let mut v = Vec :: with_capacity_in ( n, alloc) ;
2048
- v. extend_with ( n, ExtendElement ( elem) ) ;
2049
- v
2050
- }
2051
- }
2052
-
2053
2002
////////////////////////////////////////////////////////////////////////////////
2054
2003
// Common trait implementations for Vec
2055
2004
////////////////////////////////////////////////////////////////////////////////
0 commit comments