Skip to content

Commit 2002514

Browse files
committed
Add ensure_capacity() to Buffer
1 parent af038a5 commit 2002514

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

plinth-core/src/buffers/buffer.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ impl Buffer {
4242
self.samples[0].capacity()
4343
}
4444

45+
/// Never lowers capacity
46+
pub fn ensure_capacity(&mut self, capacity: usize) {
47+
if capacity <= self.capacity() {
48+
return;
49+
}
50+
51+
let additional = capacity - self.capacity();
52+
self.reserve(additional);
53+
}
54+
4555
pub fn resize(&mut self, length: usize) {
4656
for channel in self.samples.iter_mut() {
4757
channel.resize(length, 0.0);

0 commit comments

Comments
 (0)