Skip to content

Commit 8d47fa3

Browse files
committed
Reuse Vec<Pipe> allocation across resets (#87)
Prior to this PR, a new `Vec<Pipe>` is allocated every time the screen is reset. Now, the same allocation is reused across `App::reset_loop` calls, meaning only one `Vec<Pipe>` is ever created.
1 parent 3eee233 commit 8d47fa3

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

crates/pipes-rs/src/lib.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ impl<B: Backend> App<B> {
4141
self.terminal.enable_bold()?;
4242
}
4343

44+
let mut pipes = self.create_pipes();
45+
4446
loop {
45-
if let ControlFlow::Break = self.reset_loop()? {
47+
if let ControlFlow::Break = self.reset_loop(&mut pipes)? {
4648
break;
4749
}
4850
}
@@ -54,12 +56,15 @@ impl<B: Backend> App<B> {
5456
Ok(())
5557
}
5658

57-
pub fn reset_loop(&mut self) -> anyhow::Result<ControlFlow> {
59+
pub fn reset_loop(&mut self, pipes: &mut Vec<Pipe>) -> anyhow::Result<ControlFlow> {
5860
self.terminal.clear()?;
59-
let mut pipes = self.create_pipes();
61+
62+
for pipe in &mut *pipes {
63+
*pipe = self.create_pipe();
64+
}
6065

6166
while self.under_threshold() {
62-
let control_flow = self.tick_loop(&mut pipes)?;
67+
let control_flow = self.tick_loop(pipes)?;
6368
match control_flow {
6469
ControlFlow::Break | ControlFlow::Reset => return Ok(control_flow),
6570
ControlFlow::Continue => {}

0 commit comments

Comments
 (0)