about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2016-09-24 15:17:07 -0700
committerGitHub <noreply@github.com>2016-09-24 15:17:07 -0700
commita0843d7210f41974a0a2bc6876c538718404c268 (patch)
tree42bc0f89e06e23038057ee5ceeb30101ee12eda6
parent05c2fdd64f3f4acc358b653616de6034eced49b5 (diff)
parentcf50f5f965c3d3dc56fce25f2eaf8f66194f69e4 (diff)
downloadrust-a0843d7210f41974a0a2bc6876c538718404c268.tar.gz
rust-a0843d7210f41974a0a2bc6876c538718404c268.zip
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?
-rw-r--r--src/libarena/lib.rs17
1 files changed, 3 insertions, 14 deletions
diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs
index 556757ec84d..4986c9850d7 100644
--- a/src/libarena/lib.rs
+++ b/src/libarena/lib.rs
@@ -52,9 +52,6 @@ use alloc::raw_vec::RawVec;
 
 /// An arena that can hold objects of only one type.
 pub struct TypedArena<T> {
-    /// The capacity of the first chunk (once it is allocated).
-    first_chunk_capacity: usize,
-
     /// A pointer to the next object to be allocated.
     ptr: Cell<*mut T>,
 
@@ -122,17 +119,7 @@ impl<T> TypedArena<T> {
     /// Creates a new `TypedArena`.
     #[inline]
     pub fn new() -> TypedArena<T> {
-        // Reserve at least one page.
-        let elem_size = cmp::max(1, mem::size_of::<T>());
-        TypedArena::with_capacity(PAGE / elem_size)
-    }
-
-    /// Creates a new `TypedArena`. Each chunk used within the arena will have
-    /// space for at least the given number of objects.
-    #[inline]
-    pub fn with_capacity(capacity: usize) -> TypedArena<T> {
         TypedArena {
-            first_chunk_capacity: cmp::max(1, capacity),
             // We set both `ptr` and `end` to 0 so that the first call to
             // alloc() will trigger a grow().
             ptr: Cell::new(0 as *mut T),
@@ -183,7 +170,8 @@ impl<T> TypedArena<T> {
                     new_capacity = prev_capacity.checked_mul(2).unwrap();
                 }
             } else {
-                new_capacity = self.first_chunk_capacity;
+                let elem_size = cmp::max(1, mem::size_of::<T>());
+                new_capacity = cmp::max(1, PAGE / elem_size);
             }
             chunk = TypedArenaChunk::<T>::new(new_capacity);
             self.ptr.set(chunk.start());
@@ -191,6 +179,7 @@ impl<T> TypedArena<T> {
             chunks.push(chunk);
         }
     }
+
     /// Clears the arena. Deallocates all but the longest chunk which may be reused.
     pub fn clear(&mut self) {
         unsafe {