Skip to content

Commit a0843d7

Browse files
authored
Auto merge of #36657 - nnethercote:rm-TypedArena-with_capacity, r=eddyb
[breaking-change] Remove TypedArena::with_capacity This is a follow-up to #36592. The function is unused by rustc. Also, it doesn't really follow the usual meaning of a `with_capacity` function because the first chunk allocation is now delayed until the first `alloc` call. This change reduces the size of `TypedArena` by one `usize`. @eddyb: we discussed this on IRC. Would you like to review it?
2 parents 05c2fdd + cf50f5f commit a0843d7

File tree

1 file changed

+3
-14
lines changed

1 file changed

+3
-14
lines changed

src/libarena/lib.rs

+3-14
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ use alloc::raw_vec::RawVec;
5252

5353
/// An arena that can hold objects of only one type.
5454
pub struct TypedArena<T> {
55-
/// The capacity of the first chunk (once it is allocated).
56-
first_chunk_capacity: usize,
57-
5855
/// A pointer to the next object to be allocated.
5956
ptr: Cell<*mut T>,
6057

@@ -122,17 +119,7 @@ impl<T> TypedArena<T> {
122119
/// Creates a new `TypedArena`.
123120
#[inline]
124121
pub fn new() -> TypedArena<T> {
125-
// Reserve at least one page.
126-
let elem_size = cmp::max(1, mem::size_of::<T>());
127-
TypedArena::with_capacity(PAGE / elem_size)
128-
}
129-
130-
/// Creates a new `TypedArena`. Each chunk used within the arena will have
131-
/// space for at least the given number of objects.
132-
#[inline]
133-
pub fn with_capacity(capacity: usize) -> TypedArena<T> {
134122
TypedArena {
135-
first_chunk_capacity: cmp::max(1, capacity),
136123
// We set both `ptr` and `end` to 0 so that the first call to
137124
// alloc() will trigger a grow().
138125
ptr: Cell::new(0 as *mut T),
@@ -183,14 +170,16 @@ impl<T> TypedArena<T> {
183170
new_capacity = prev_capacity.checked_mul(2).unwrap();
184171
}
185172
} else {
186-
new_capacity = self.first_chunk_capacity;
173+
let elem_size = cmp::max(1, mem::size_of::<T>());
174+
new_capacity = cmp::max(1, PAGE / elem_size);
187175
}
188176
chunk = TypedArenaChunk::<T>::new(new_capacity);
189177
self.ptr.set(chunk.start());
190178
self.end.set(chunk.end());
191179
chunks.push(chunk);
192180
}
193181
}
182+
194183
/// Clears the arena. Deallocates all but the longest chunk which may be reused.
195184
pub fn clear(&mut self) {
196185
unsafe {

0 commit comments

Comments
 (0)