Add TODOs, move function
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by sharkdp · committed by sharkdp · parent a85f33c · Browse files · 2 files·+16 added−13 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+16 added−13 removed
- other:+16 added−13 removed
Provenance
- Commit
2ea77e7- Tree
04f2b84- Author
sharkdp <davidpeter@web.de>- Committer
sharkdp <davidpeter@web.de>- Parent
a85f33c
2 files changed+16 added−13 removed
modified:src/filesystem.rs+9 added
91 unmodified lines92 }93 iter.as_path()94 }95 96+pub fn replace_path_separator<'a>(path_separator: &Option<String>, path: &mut Cow<'a, str>) {97+ match &path_separator {98+ None => {}99+ Some(sep) => {100+ *path.to_mut() = path.replace(std::path::MAIN_SEPARATOR, &sep);101+ }102+ }103+}104+105 #[cfg(test)]106 mod tests {107 use super::strip_current_dir;108 use std::path::{Path, PathBuf};15 unmodified linesmodified:src/output.rs+7 added-13 removed
1-use std::borrow::Cow;1 use std::io::{self, StdoutLock, Write};2 use std::path::{Path, PathBuf};3 use std::process;4 use std::sync::atomic::{AtomicBool, Ordering};2 unmodified lines7 use ansi_term;8 use lscolors::{LsColors, Style};9 10 use crate::exit_codes::ExitCode;12-use crate::filesystem::strip_current_dir;11+use crate::filesystem::{replace_path_separator, strip_current_dir};12 use crate::options::Options;13 14+// TODO: this function is performance critical and can probably be optimized15 pub fn print_entry(16 stdout: &mut StdoutLock,17 entry: &PathBuf,18 config: &Options,16 unmodified lines35 process::exit(ExitCode::GeneralError.into());36 }37 }38 39-fn replace_path_separator<'a>(config: &Options, path: &mut Cow<'a, str>) {40- match &config.path_separator {41- None => {}42- Some(sep) => {43- *path.to_mut() = path.replace(std::path::MAIN_SEPARATOR, &sep);44- }45- }46-}47-39+// TODO: this function is performance critical and can probably be optimized40 fn print_entry_colorized(41 stdout: &mut StdoutLock,42 path: &Path,43 config: &Options,8 unmodified lines52 .map(Style::to_ansi_term_style)53 .unwrap_or(default_style);54 55 let mut path_string = component.to_string_lossy();64- replace_path_separator(&config, &mut path_string);56+ replace_path_separator(&config.path_separator, &mut path_string);57 write!(stdout, "{}", style.paint(path_string))?;58 59+ // TODO: can we move this out of the if-statement? Why do we call it that often?60 if wants_to_quit.load(Ordering::Relaxed) {61 writeln!(stdout)?;62 process::exit(ExitCode::KilledBySigint.into());63 }5 unmodified lines69 writeln!(stdout)70 }71 }72 73+// TODO: this function is performance critical and can probably be optimized74 fn print_entry_uncolorized(75 stdout: &mut StdoutLock,76 path: &Path,77 config: &Options,78 ) -> io::Result<()> {79 let separator = if config.null_separator { "\0" } else { "\n" };80 81 let mut path_str = path.to_string_lossy();88- replace_path_separator(&config, &mut path_str);82+ replace_path_separator(&config.path_separator, &mut path_str);83 write!(stdout, "{}{}", path_str, separator)84 }