From 51f6c84689af51ac37613cb62e792760a7be9d61 Mon Sep 17 00:00:00 2001 From: overlookmotel <557937+overlookmotel@users.noreply.github.com> Date: Fri, 15 Aug 2025 18:08:52 +0000 Subject: [PATCH] refactor(allocator): rename vars and comments in `AllocatorPool` (#13129) Pure refactor. Rename `AllocatorPool::new`'s `size` param to `thread_count`, which is more descriptive. Improve comments for this method. --- crates/oxc_allocator/src/pool.rs | 6 +++--- crates/oxc_allocator/src/pool_fixed_size.rs | 9 +++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/oxc_allocator/src/pool.rs b/crates/oxc_allocator/src/pool.rs index b3044edd126f1..1e9ad1cbe5baf 100644 --- a/crates/oxc_allocator/src/pool.rs +++ b/crates/oxc_allocator/src/pool.rs @@ -10,9 +10,9 @@ pub struct AllocatorPool { } impl AllocatorPool { - /// Creates a new [`AllocatorPool`] pre-filled with the given number of default [`Allocator`] instances. - pub fn new(size: usize) -> AllocatorPool { - let allocators = iter::repeat_with(Allocator::new).take(size).collect(); + /// Creates a new [`AllocatorPool`] for use across the specified number of threads. + pub fn new(thread_count: usize) -> AllocatorPool { + let allocators = iter::repeat_with(Allocator::new).take(thread_count).collect(); AllocatorPool { allocators: Mutex::new(allocators) } } diff --git a/crates/oxc_allocator/src/pool_fixed_size.rs b/crates/oxc_allocator/src/pool_fixed_size.rs index a4645d390a978..a69fdbe9fd151 100644 --- a/crates/oxc_allocator/src/pool_fixed_size.rs +++ b/crates/oxc_allocator/src/pool_fixed_size.rs @@ -30,10 +30,11 @@ pub struct AllocatorPool { } impl AllocatorPool { - /// Creates a new [`AllocatorPool`] with capacity for the given number of `FixedSizeAllocator` instances. - pub fn new(size: usize) -> AllocatorPool { - // Each allocator consumes a large block of memory, so create them on demand instead of upfront - let allocators = Vec::with_capacity(size); + /// Creates a new [`AllocatorPool`] for use across the specified number of threads. + pub fn new(thread_count: usize) -> AllocatorPool { + // Each allocator consumes a large block of memory, so create them on demand instead of upfront, + // in case not all threads end up being used (e.g. language server without `import` plugin) + let allocators = Vec::with_capacity(thread_count); AllocatorPool { allocators: Mutex::new(allocators), next_id: AtomicU32::new(0) } }