Skip to content
Myr

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

2 files+16 added−13 removed

modified:src/filesystem.rs+9 added
91 unmodified lines
92 }93 iter.as_path()94}9596pub 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}104105#[cfg(test)]106mod tests {107 use super::strip_current_dir;108 use std::path::{Path, PathBuf};
15 unmodified lines
modified:src/output.rs+7 added-13 removed
1use std::borrow::Cow;1use std::io::{self, StdoutLock, Write};2use std::path::{Path, PathBuf};3use std::process;4use std::sync::atomic::{AtomicBool, Ordering};
2 unmodified lines
7use ansi_term;8use lscolors::{LsColors, Style};910use crate::exit_codes::ExitCode;12use crate::filesystem::strip_current_dir;11use crate::filesystem::{replace_path_separator, strip_current_dir};12use crate::options::Options;1314// TODO: this function is performance critical and can probably be optimized15pub fn print_entry(16 stdout: &mut StdoutLock,17 entry: &PathBuf,18 config: &Options,
16 unmodified lines
35 process::exit(ExitCode::GeneralError.into());36 }37}3839fn 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}4739// TODO: this function is performance critical and can probably be optimized40fn print_entry_colorized(41 stdout: &mut StdoutLock,42 path: &Path,43 config: &Options,
8 unmodified lines
52 .map(Style::to_ansi_term_style)53 .unwrap_or(default_style);5455 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))?;5859 // 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 lines
69 writeln!(stdout)70 }71}7273// TODO: this function is performance critical and can probably be optimized74fn 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" };8081 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}