Skip to content

Commit

Permalink
Merge pull request #55 from Sorseg/master
Browse files Browse the repository at this point in the history
Add allocate implementation
  • Loading branch information
SamiPerttu authored Sep 22, 2024
2 parents 0df9e07 + 303b004 commit 353415c
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/sequencer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,20 +266,24 @@ impl Clone for Sequencer {
}
}

const DEFAULT_CAPACITY: usize = 16384;

impl Sequencer {
/// Create a new sequencer. The sequencer has zero inputs.
/// The number of outputs is decided by the user.
/// If `replay_events` is true, then past events will be retained
/// and played back after a reset.
/// If false, then all events will be cleared on reset.
pub fn new(replay_events: bool, outputs: usize) -> Self {
// when adding new dynamically sized fields,
// don't forget to update [AudioUnit::allocate] implementation
Self {
active: Vec::with_capacity(16384),
active_map: HashMap::with_capacity(16384),
active: Vec::with_capacity(DEFAULT_CAPACITY),
active_map: HashMap::with_capacity(DEFAULT_CAPACITY),
active_threshold: -f64::INFINITY,
ready: BinaryHeap::with_capacity(16384),
past: Vec::with_capacity(16384),
edit_map: HashMap::with_capacity(16384),
ready: BinaryHeap::with_capacity(DEFAULT_CAPACITY),
past: Vec::with_capacity(DEFAULT_CAPACITY),
edit_map: HashMap::with_capacity(DEFAULT_CAPACITY),
outputs,
time: 0.0,
sample_rate: DEFAULT_SR,
Expand Down Expand Up @@ -798,6 +802,14 @@ impl AudioUnit for Sequencer {
fn footprint(&self) -> usize {
core::mem::size_of::<Self>()
}

fn allocate(&mut self) {
self.active.reserve(DEFAULT_CAPACITY);
self.active_map.reserve(DEFAULT_CAPACITY);
self.ready.reserve(DEFAULT_CAPACITY);
self.past.reserve(DEFAULT_CAPACITY);
self.edit_map.reserve(DEFAULT_CAPACITY);
}
}

#[cfg(test)]
Expand Down

0 comments on commit 353415c

Please sign in to comment.