@@ -44,23 +44,6 @@ fn outline<F: FnOnce() -> R, R>(f: F) -> R {
44
44
f ( )
45
45
}
46
46
47
- /// An arena that can hold objects of only one type.
48
- pub struct TypedArena < T > {
49
- /// A pointer to the next object to be allocated.
50
- ptr : Cell < * mut T > ,
51
-
52
- /// A pointer to the end of the allocated area. When this pointer is
53
- /// reached, a new chunk is allocated.
54
- end : Cell < * mut T > ,
55
-
56
- /// A vector of arena chunks.
57
- chunks : RefCell < Vec < ArenaChunk < T > > > ,
58
-
59
- /// Marker indicating that dropping the arena causes its owned
60
- /// instances of `T` to be dropped.
61
- _own : PhantomData < T > ,
62
- }
63
-
64
47
struct ArenaChunk < T = u8 > {
65
48
/// The raw storage for the arena chunk.
66
49
storage : NonNull < [ MaybeUninit < T > ] > ,
@@ -130,20 +113,6 @@ impl<T> ArenaChunk<T> {
130
113
const PAGE : usize = 4096 ;
131
114
const HUGE_PAGE : usize = 2 * 1024 * 1024 ;
132
115
133
- impl < T > Default for TypedArena < T > {
134
- /// Creates a new `TypedArena`.
135
- fn default ( ) -> TypedArena < T > {
136
- TypedArena {
137
- // We set both `ptr` and `end` to 0 so that the first call to
138
- // alloc() will trigger a grow().
139
- ptr : Cell :: new ( ptr:: null_mut ( ) ) ,
140
- end : Cell :: new ( ptr:: null_mut ( ) ) ,
141
- chunks : Default :: default ( ) ,
142
- _own : PhantomData ,
143
- }
144
- }
145
- }
146
-
147
116
trait IterExt < T > {
148
117
fn alloc_from_iter ( self , arena : & TypedArena < T > ) -> & mut [ T ] ;
149
118
}
@@ -215,6 +184,37 @@ impl<A: smallvec::Array> IterExt<A::Item> for SmallVec<A> {
215
184
}
216
185
}
217
186
187
+ /// An arena that can hold objects of only one type.
188
+ pub struct TypedArena < T > {
189
+ /// A pointer to the next object to be allocated.
190
+ ptr : Cell < * mut T > ,
191
+
192
+ /// A pointer to the end of the allocated area. When this pointer is
193
+ /// reached, a new chunk is allocated.
194
+ end : Cell < * mut T > ,
195
+
196
+ /// A vector of arena chunks.
197
+ chunks : RefCell < Vec < ArenaChunk < T > > > ,
198
+
199
+ /// Marker indicating that dropping the arena causes its owned
200
+ /// instances of `T` to be dropped.
201
+ _own : PhantomData < T > ,
202
+ }
203
+
204
+ impl < T > Default for TypedArena < T > {
205
+ /// Creates a new `TypedArena`.
206
+ fn default ( ) -> TypedArena < T > {
207
+ TypedArena {
208
+ // We set both `ptr` and `end` to 0 so that the first call to
209
+ // alloc() will trigger a grow().
210
+ ptr : Cell :: new ( ptr:: null_mut ( ) ) ,
211
+ end : Cell :: new ( ptr:: null_mut ( ) ) ,
212
+ chunks : Default :: default ( ) ,
213
+ _own : PhantomData ,
214
+ }
215
+ }
216
+ }
217
+
218
218
impl < T > TypedArena < T > {
219
219
/// Allocates an object in the `TypedArena`, returning a reference to it.
220
220
#[ inline]
0 commit comments