Skip to content

Commit 81cdfeb

Browse files
committed
Rename marked_for_update -> layout_update_flags
Also remove the unnecessary flag vector reallocation
1 parent 5b05da9 commit 81cdfeb

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

omni-led-lib/src/script_handler/script_handler.rs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ struct DeviceContext {
3131
name: String,
3232
layouts: Vec<Layout>,
3333
animation_groups: Vec<HashMap<usize, AnimationGroup>>,
34-
marked_for_update: Vec<bool>,
34+
layout_update_flags: Vec<bool>,
3535
time_remaining: Duration,
3636
last_priority: usize,
3737
state: State,
@@ -116,7 +116,7 @@ impl ScriptHandler {
116116
for device in &mut self.devices {
117117
for (index, layout) in device.layouts.iter().enumerate() {
118118
if layout.run_on.contains(key) {
119-
device.marked_for_update[index] = true;
119+
device.layout_update_flags[index] = true;
120120
}
121121
}
122122
}
@@ -133,7 +133,9 @@ impl ScriptHandler {
133133
fn reset(&mut self, device_name: &String) {
134134
match self.devices.iter_mut().find(|x| x.name == *device_name) {
135135
Some(ctx) => {
136-
ctx.marked_for_update = vec![false; ctx.marked_for_update.len()];
136+
for marked_for_update in &mut ctx.layout_update_flags {
137+
*marked_for_update = false;
138+
}
137139
ctx.time_remaining = Duration::ZERO;
138140
ctx.last_priority = 0;
139141
ctx.state = State::Finished;
@@ -144,7 +146,7 @@ impl ScriptHandler {
144146
}
145147
}
146148

147-
pub(self) fn register(
149+
fn register(
148150
&mut self,
149151
lua: &Lua,
150152
device_name: String,
@@ -160,7 +162,7 @@ impl ScriptHandler {
160162
name: device_name,
161163
layouts,
162164
animation_groups: vec![HashMap::new(); layout_count],
163-
marked_for_update: vec![false; layout_count],
165+
layout_update_flags: vec![false; layout_count],
164166
time_remaining: Default::default(),
165167
last_priority: 0,
166168
state: State::Finished,
@@ -188,18 +190,15 @@ impl ScriptHandler {
188190
ctx.time_remaining = ctx.time_remaining.saturating_sub(time_passed);
189191
let has_time_remaining = !ctx.time_remaining.is_zero();
190192

191-
let mut marked_for_update = vec![false; ctx.marked_for_update.len()];
192-
std::mem::swap(&mut ctx.marked_for_update, &mut marked_for_update);
193-
194193
let mut to_update = None;
195194
let mut new_update = false;
196-
for (priority, marked_for_update) in marked_for_update.into_iter().enumerate() {
195+
for (priority, marked_for_update) in ctx.layout_update_flags.iter().enumerate() {
197196
// If a more important layout still has time remaining, don't bother checking further
198197
if has_time_remaining && ctx.last_priority < priority {
199198
break;
200199
}
201200

202-
if marked_for_update && Self::test_predicate(&ctx.layouts[priority].predicate)? {
201+
if *marked_for_update && Self::test_predicate(&ctx.layouts[priority].predicate)? {
203202
to_update = Some(priority);
204203
new_update = true;
205204
break;
@@ -220,6 +219,10 @@ impl ScriptHandler {
220219
}
221220
}
222221

222+
for marked_for_update in &mut ctx.layout_update_flags {
223+
*marked_for_update = false;
224+
}
225+
223226
let to_update = match to_update {
224227
Some(to_update) => to_update,
225228
None => return Ok(()),

0 commit comments

Comments
 (0)