Skip to content

Commit

Permalink
perf: Use drain instead of remove in chart examples (#922)
Browse files Browse the repository at this point in the history
  • Loading branch information
mo8it committed Feb 5, 2024
1 parent 61a8278 commit 0963463
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
10 changes: 4 additions & 6 deletions examples/chart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,12 @@ impl App {
}

fn on_tick(&mut self) {
for _ in 0..5 {
self.data1.remove(0);
}
self.data1.drain(0..5);
self.data1.extend(self.signal1.by_ref().take(5));
for _ in 0..10 {
self.data2.remove(0);
}

self.data2.drain(0..10);
self.data2.extend(self.signal2.by_ref().take(10));

self.window[0] += 1.0;
self.window[1] += 1.0;
}
Expand Down
4 changes: 1 addition & 3 deletions examples/demo/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,7 @@ where
S: Iterator,
{
fn on_tick(&mut self) {
for _ in 0..self.tick_rate {
self.points.remove(0);
}
self.points.drain(0..self.tick_rate);
self.points
.extend(self.source.by_ref().take(self.tick_rate));
}
Expand Down

0 comments on commit 0963463

Please sign in to comment.