Skip to content

Commit

Permalink
Avoid deallocation a potentially big hashmap
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed May 31, 2020
1 parent 31778d7 commit 91aade3
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,18 @@ fn run() -> Result<(), Error> {
paths_from(input)?,
Interaction::Full,
)?
.map(|(keys_rx, mut app)| app.process_events(&mut terminal, keys_rx.into_iter()));
.map(|(keys_rx, mut app)| {
let res = app.process_events(&mut terminal, keys_rx.into_iter());
// Leak app memory to avoid having to wait for the hashmap to deallocate, which causes a noticable delay shortly before the the
// program exits anyway.
std::mem::forget(app);
res
});

drop(terminal);
io::stdout().flush().ok();

// Exit 'quickly' to avoid having to wait for all memory to be freed by us.
// Let the OS do it - we have nothing to lose, literally.
// Exit 'quickly' to avoid having to not have to deal with slightly different types in the other match branches
std::process::exit(res.transpose()?.map(|e| e.to_exit_code()).unwrap_or(0));
}
Some(Aggregate {
Expand Down

0 comments on commit 91aade3

Please sign in to comment.