bugfix: Remove the heap allocation from non-single queues

This commit is contained in:
Irine 2023-11-16 06:08:17 +04:00 committed by GitHub
parent 22b5e83c4f
commit c0e1098aa0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -57,7 +57,6 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
use alloc::boxed::Box;
use core::fmt;
use core::panic::{RefUnwindSafe, UnwindSafe};
use sync::atomic::{self, Ordering};
@ -101,10 +100,11 @@ unsafe impl<T: Send> Sync for ConcurrentQueue<T> {}
impl<T> UnwindSafe for ConcurrentQueue<T> {}
impl<T> RefUnwindSafe for ConcurrentQueue<T> {}
#[allow(clippy::large_enum_variant)]
enum Inner<T> {
Single(Single<T>),
Bounded(Box<Bounded<T>>),
Unbounded(Box<Unbounded<T>>),
Bounded(Bounded<T>),
Unbounded(Unbounded<T>),
}
impl<T> ConcurrentQueue<T> {
@ -127,7 +127,7 @@ impl<T> ConcurrentQueue<T> {
if cap == 1 {
ConcurrentQueue(Inner::Single(Single::new()))
} else {
ConcurrentQueue(Inner::Bounded(Box::new(Bounded::new(cap))))
ConcurrentQueue(Inner::Bounded(Bounded::new(cap)))
}
}
@ -141,7 +141,7 @@ impl<T> ConcurrentQueue<T> {
/// let q = ConcurrentQueue::<i32>::unbounded();
/// ```
pub fn unbounded() -> ConcurrentQueue<T> {
ConcurrentQueue(Inner::Unbounded(Box::new(Unbounded::new())))
ConcurrentQueue(Inner::Unbounded(Unbounded::new()))
}
/// Attempts to push an item into the queue.