Skip to content
Myr

output: Remove wants_to_quit handling from print_entry()

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Since we only check it once per path now, we might as well just check it before printing anything.

authored by Tavian Barnes · committed by Tavian Barnes · parent a4bb734 · Browse files · 2 files+14 added−19 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+14 added−19 removed

  • other:+14 added−19 removed

2 files+14 added−19 removed

modified:src/output.rs+2 added-15 removed
1use std::borrow::Cow;2use std::io::{self, Write};3use std::path::Path;4use std::sync::atomic::{AtomicBool, Ordering};45use lscolors::{Indicator, LsColors, Style};67use crate::config::Config;
5 unmodified lines
13 path.replace(std::path::MAIN_SEPARATOR, new_path_separator)14}1516// TODO: this function is performance critical and can probably be optimized18pub fn print_entry<W: Write>(19 stdout: &mut W,20 entry: &Path,21 config: &Config,22 wants_to_quit: &AtomicBool,23) {17pub fn print_entry<W: Write>(stdout: &mut W, entry: &Path, config: &Config) {18 let path = if config.strip_cwd_prefix {19 strip_current_dir(entry)20 } else {21 entry22 };2324 let r = if let Some(ref ls_colors) = config.ls_colors {31 print_entry_colorized(stdout, path, config, ls_colors, wants_to_quit)25 print_entry_colorized(stdout, path, config, ls_colors)26 } else {27 print_entry_uncolorized(stdout, path, config)28 };29
13 unmodified lines
43 stdout: &mut W,44 path: &Path,45 config: &Config,46 ls_colors: &LsColors,53 wants_to_quit: &AtomicBool,47) -> io::Result<()> {48 // Split the path between the parent and the last component49 let mut offset = 0;50 let path_str = path.to_string_lossy();
33 unmodified lines
84 } else {85 writeln!(stdout)?;86 }8795 if wants_to_quit.load(Ordering::Relaxed) {96 // Ignore any errors on flush, because we're about to exit anyway97 let _ = stdout.flush();98 ExitCode::KilledBySigint.exit();99 }10088 Ok(())89}9091// TODO: this function is performance critical and can probably be optimized
41 unmodified lines
modified:src/walk.rs+12 added-4 removed
242 unmodified lines
243 self.stream()?;244 }245 }246 ReceiverMode::Streaming => {247 self.print(&path);247 self.print(&path)?;248 self.flush()?;249 }250 }251
20 unmodified lines
272 Ok(())273 }274275 /// Output a path.276 fn print(&mut self, path: &Path) {277 output::print_entry(&mut self.stdout, path, &self.config, &self.wants_to_quit)276 fn print(&mut self, path: &Path) -> Result<(), ExitCode> {277 output::print_entry(&mut self.stdout, path, &self.config);278279 if self.wants_to_quit.load(Ordering::Relaxed) {280 // Ignore any errors on flush, because we're about to exit anyway281 let _ = self.flush();282 return Err(ExitCode::KilledBySigint);283 }284285 Ok(())286 }287288 /// Switch ourselves into streaming mode.289 fn stream(&mut self) -> Result<(), ExitCode> {290 self.mode = ReceiverMode::Streaming;291292 let buffer = mem::take(&mut self.buffer);293 for path in buffer {286 self.print(&path);294 self.print(&path)?;295 }296297 self.flush()298 }
314 unmodified lines