Skip to content

Commit 15efbaf

Browse files
committed
Move TypedArena decl and its Default impl next to other impls.
1 parent 3c5b8e1 commit 15efbaf

File tree

1 file changed

+31
-31
lines changed
  • compiler/rustc_arena/src

1 file changed

+31
-31
lines changed

compiler/rustc_arena/src/lib.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,6 @@ fn outline<F: FnOnce() -> R, R>(f: F) -> R {
4444
f()
4545
}
4646

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-
6447
struct ArenaChunk<T = u8> {
6548
/// The raw storage for the arena chunk.
6649
storage: NonNull<[MaybeUninit<T>]>,
@@ -130,20 +113,6 @@ impl<T> ArenaChunk<T> {
130113
const PAGE: usize = 4096;
131114
const HUGE_PAGE: usize = 2 * 1024 * 1024;
132115

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-
147116
trait IterExt<T> {
148117
fn alloc_from_iter(self, arena: &TypedArena<T>) -> &mut [T];
149118
}
@@ -215,6 +184,37 @@ impl<A: smallvec::Array> IterExt<A::Item> for SmallVec<A> {
215184
}
216185
}
217186

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+
218218
impl<T> TypedArena<T> {
219219
/// Allocates an object in the `TypedArena`, returning a reference to it.
220220
#[inline]

0 commit comments

Comments
 (0)