Skip to content

Commit a1f0270

Browse files
committed
Actually remove the Alloc reference in channel data
1 parent 8cbf583 commit a1f0270

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

src/render/quantum.rs

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@ use crate::assert_valid_number_of_channels;
99
use crate::{MAX_CHANNELS, RENDER_QUANTUM_SIZE};
1010

1111
// object pool for `AudioRenderQuantumChannel`s, only allocate if the pool is empty
12-
pub(crate) struct Alloc {
13-
inner: Rc<AllocInner>,
14-
}
15-
16-
#[derive(Debug)]
17-
struct AllocInner {}
12+
pub(crate) struct Alloc;
1813

1914
thread_local! {
2015
static POOL: RefCell<Vec<Rc<[f32; RENDER_QUANTUM_SIZE]>>> = RefCell::new(Vec::with_capacity(32));
@@ -23,26 +18,17 @@ thread_local! {
2318

2419
impl Alloc {
2520
pub fn with_capacity(n: usize) -> Self {
26-
let pool: Vec<_> = (0..n).map(|_| Rc::new([0.; RENDER_QUANTUM_SIZE])).collect();
27-
POOL.set(pool);
28-
29-
Self {
30-
inner: Rc::new(AllocInner {}),
31-
}
21+
Self {}
3222
}
3323

3424
#[cfg(test)]
3525
pub fn allocate(&self) -> AudioRenderQuantumChannel {
36-
AudioRenderQuantumChannel {
37-
data: self.inner.allocate(),
38-
alloc: Rc::clone(&self.inner),
39-
}
26+
AudioRenderQuantumChannel { data: allocate() }
4027
}
4128

4229
pub fn silence(&self) -> AudioRenderQuantumChannel {
4330
AudioRenderQuantumChannel {
4431
data: ZEROES.with(Rc::clone),
45-
alloc: Rc::clone(&self.inner),
4632
}
4733
}
4834

@@ -52,20 +38,18 @@ impl Alloc {
5238
}
5339
}
5440

55-
impl AllocInner {
56-
fn allocate(&self) -> Rc<[f32; RENDER_QUANTUM_SIZE]> {
57-
if let Some(rc) = POOL.with_borrow_mut(|p| p.pop()) {
58-
// reuse from pool
59-
rc
60-
} else {
61-
// allocate
62-
Rc::new([0.; RENDER_QUANTUM_SIZE])
63-
}
41+
fn allocate() -> Rc<[f32; RENDER_QUANTUM_SIZE]> {
42+
if let Some(rc) = POOL.with_borrow_mut(|p| p.pop()) {
43+
// reuse from pool
44+
rc
45+
} else {
46+
// allocate
47+
Rc::new([0.; RENDER_QUANTUM_SIZE])
6448
}
49+
}
6550

66-
fn push(&self, data: Rc<[f32; RENDER_QUANTUM_SIZE]>) {
67-
POOL.with_borrow_mut(|p| p.push(data));
68-
}
51+
fn push(data: Rc<[f32; RENDER_QUANTUM_SIZE]>) {
52+
POOL.with_borrow_mut(|p| p.push(data));
6953
}
7054

7155
/// Render thread channel buffer
@@ -84,13 +68,12 @@ impl AllocInner {
8468
#[derive(Clone, Debug)]
8569
pub struct AudioRenderQuantumChannel {
8670
data: Rc<[f32; RENDER_QUANTUM_SIZE]>,
87-
alloc: Rc<AllocInner>,
8871
}
8972

9073
impl AudioRenderQuantumChannel {
9174
fn make_mut(&mut self) -> &mut [f32; RENDER_QUANTUM_SIZE] {
9275
if Rc::strong_count(&self.data) != 1 {
93-
let mut new = self.alloc.allocate();
76+
let mut new = allocate();
9477
Rc::make_mut(&mut new).copy_from_slice(self.data.deref());
9578
self.data = new;
9679
}
@@ -117,7 +100,6 @@ impl AudioRenderQuantumChannel {
117100
pub(crate) fn silence(&self) -> Self {
118101
Self {
119102
data: ZEROES.with(Rc::clone),
120-
alloc: Rc::clone(&self.alloc),
121103
}
122104
}
123105
}
@@ -149,7 +131,7 @@ impl std::ops::Drop for AudioRenderQuantumChannel {
149131
if Rc::strong_count(&self.data) == 1 {
150132
let zeroes = ZEROES.with(Rc::clone);
151133
let rc = std::mem::replace(&mut self.data, zeroes);
152-
self.alloc.push(rc);
134+
push(rc);
153135
}
154136
}
155137
}

0 commit comments

Comments
 (0)