Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions crates/oxc_allocator/src/pool/fixed_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,12 @@ impl FixedSizeAllocatorPool {
/// * Panics if the underlying mutex is poisoned.
pub fn get(&self) -> Allocator {
// Try to get an allocator from the pool
{
let maybe_allocator = self.allocators.lock().unwrap().pop();
if let Some(allocator) = maybe_allocator {
return allocator.into_inner();
}
let maybe_allocator = {
let mut allocators = self.allocators.lock().unwrap();
allocators.pop()
};
if let Some(allocator) = maybe_allocator {
return allocator.into_inner();
}

// Pool is empty. Try to create a new allocator.
Expand All @@ -87,8 +88,11 @@ impl FixedSizeAllocatorPool {

// Pool cannot produce another allocator. Wait for an existing allocator to be returned to the pool.
loop {
let mut maybe_allocator = self.available.wait(self.allocators.lock().unwrap()).unwrap();
if let Some(allocator) = maybe_allocator.pop() {
let maybe_allocator = {
let mut allocators = self.available.wait(self.allocators.lock().unwrap()).unwrap();
allocators.pop()
};
if let Some(allocator) = maybe_allocator {
return allocator.into_inner();
}
}
Expand Down
Loading