1
1
#![ unstable( feature = "raw_vec_internals" , reason = "implementation detail" , issue = "0" ) ]
2
2
#![ doc( hidden) ]
3
3
4
- #![ feature( const_if_match) ]
5
-
6
4
use core:: cmp;
7
5
use core:: mem;
8
6
use core:: ops:: Drop ;
@@ -53,9 +51,14 @@ pub struct RawVec<T, A: Alloc = Global> {
53
51
impl < T , A : Alloc > RawVec < T , A > {
54
52
/// Like `new`, but parameterized over the choice of allocator for
55
53
/// the returned `RawVec`.
56
- #[ cfg( not( bootstrap) ) ]
57
54
pub const fn new_in ( a : A ) -> Self {
58
- let cap = if mem:: size_of :: < T > ( ) == 0 { !0 } else { 0 } ;
55
+ let cap = {
56
+ #[ cfg( not( bootstrap) ) ]
57
+ { if mem:: size_of :: < T > ( ) == 0 { !0 } else { 0 } }
58
+
59
+ #[ cfg( bootstrap) ]
60
+ [ 0 , !0 ] [ ( mem:: size_of :: < T > ( ) == 0 ) as usize ]
61
+ } ;
59
62
60
63
// `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
61
64
RawVec {
@@ -65,17 +68,6 @@ impl<T, A: Alloc> RawVec<T, A> {
65
68
}
66
69
}
67
70
68
- /// Like `new`, but parameterized over the choice of allocator for
69
- /// the returned `RawVec`.
70
- #[ cfg( bootstrap) ]
71
- pub const fn new_in ( a : A ) -> Self {
72
- RawVec {
73
- ptr : Unique :: empty ( ) ,
74
- cap : [ 0 , !0 ] [ ( mem:: size_of :: < T > ( ) == 0 ) as usize ] ,
75
- a,
76
- }
77
- }
78
-
79
71
/// Like `with_capacity`, but parameterized over the choice of
80
72
/// allocator for the returned `RawVec`.
81
73
#[ inline]
@@ -142,33 +134,8 @@ impl<T> RawVec<T, Global> {
142
134
/// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
143
135
/// `RawVec` with capacity `usize::MAX`. Useful for implementing
144
136
/// delayed allocation.
145
- #[ cfg( not( bootstrap) ) ]
146
- pub const fn new ( ) -> Self {
147
- // FIXME(Centril): Reintegrate this with `fn new_in` when we can.
148
-
149
- let cap = if mem:: size_of :: < T > ( ) == 0 { !0 } else { 0 } ;
150
-
151
- // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
152
- RawVec {
153
- ptr : Unique :: empty ( ) ,
154
- cap,
155
- a : Global ,
156
- }
157
- }
158
-
159
- /// Creates the biggest possible `RawVec` (on the system heap)
160
- /// without allocating. If `T` has positive size, then this makes a
161
- /// `RawVec` with capacity `0`. If `T` is zero-sized, then it makes a
162
- /// `RawVec` with capacity `usize::MAX`. Useful for implementing
163
- /// delayed allocation.
164
- #[ cfg( bootstrap) ]
165
137
pub const fn new ( ) -> Self {
166
- // `Unique::empty()` doubles as "unallocated" and "zero-sized allocation".
167
- RawVec {
168
- ptr : Unique :: empty ( ) ,
169
- cap : [ 0 , !0 ] [ ( mem:: size_of :: < T > ( ) == 0 ) as usize ] ,
170
- a : Global ,
171
- }
138
+ Self :: new_in ( Global )
172
139
}
173
140
174
141
/// Creates a `RawVec` (on the system heap) with exactly the
0 commit comments