diff --git a/src/bin/fish.rs b/src/bin/fish.rs index 98ab48151..5cd1e0810 100644 --- a/src/bin/fish.rs +++ b/src/bin/fish.rs @@ -518,11 +518,7 @@ fn throwing_main() -> i32 { // TODO(MSRV>=1.88): feature(let_chains) if let Some(path) = &opts.profile_startup_output { if opts.profile_startup_output != opts.profile_output { - parser.emit_profiling(path); - - // If we are profiling both, ensure the startup data only - // ends up in the startup file. - parser.clear_profiling(); + parser.flush_profiling(path); } } @@ -621,7 +617,7 @@ fn throwing_main() -> i32 { ); if let Some(profile_output) = opts.profile_output { - parser.emit_profiling(&profile_output); + parser.flush_profiling(&profile_output); } history::save_all(); diff --git a/src/parser.rs b/src/parser.rs index 55cf3a73e..02b5d958b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1119,13 +1119,8 @@ pub fn profile_items_mut(&self) -> RefMut<'_, Vec> { self.profile_items.borrow_mut() } - /// Remove the profiling items. - pub fn clear_profiling(&self) { - self.profile_items.borrow_mut().clear(); - } - - /// Output profiling data to the given filename. - pub fn emit_profiling(&self, path: &OsStr) { + /// Flush profiling data to the given filename. + pub fn flush_profiling(&self, path: &OsStr) { // Save profiling information. OK to not use CLO_EXEC here because this is called while fish is // exiting (and hence will not fork). let mut f = match std::fs::File::create(path) { @@ -1142,7 +1137,9 @@ pub fn emit_profiling(&self, path: &OsStr) { return; } }; - print_profile(&self.profile_items.borrow(), &mut f); + let mut profile_items = self.profile_items.borrow_mut(); + print_profile(&profile_items, &mut f); + profile_items.clear(); } pub fn get_backtrace(&self, src: &wstr, errors: &ParseErrorList) -> WString {