Skip to content
Myr

Compute colors in parallel

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

authored by Tavian Barnes · committed by David Peter · parent b2c8888 · Browse files · 5 files+28 added−3 removed
This commit

State

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

Diff stats

5 files+28 added−3 removed

  • other:+28 added−3 removed

5 files+28 added−3 removed

modified:src/config.rs+7 added
118 unmodified lines
119120 /// Whether or not to strip the './' prefix for search results121 pub strip_cwd_prefix: bool,122}123124impl Config {125 /// Check whether results are being printed.126 pub fn is_printing(&self) -> bool {127 self.command.is_none()128 }129}
modified:src/dir_entry.rs+11 added-1 removed
1use std::ffi::OsString;2use std::fs::{FileType, Metadata};3use std::path::{Path, PathBuf};45use lscolors::Colorable;5use lscolors::{Colorable, LsColors, Style};67use once_cell::unsync::OnceCell;89use crate::config::Config;10use crate::filesystem::strip_current_dir;
5 unmodified lines
1617pub struct DirEntry {18 inner: DirEntryInner,19 metadata: OnceCell<Option<Metadata>>,20 style: OnceCell<Option<Style>>,21}2223impl DirEntry {24 #[inline]25 pub fn normal(e: ignore::DirEntry) -> Self {26 Self {27 inner: DirEntryInner::Normal(e),28 metadata: OnceCell::new(),29 style: OnceCell::new(),30 }31 }3233 pub fn broken_symlink(path: PathBuf) -> Self {34 Self {35 inner: DirEntryInner::BrokenSymlink(path),36 metadata: OnceCell::new(),37 style: OnceCell::new(),38 }39 }4041 pub fn path(&self) -> &Path {
49 unmodified lines
91 DirEntryInner::Normal(e) => Some(e.depth()),92 DirEntryInner::BrokenSymlink(_) => None,93 }94 }9596 pub fn style(&self, ls_colors: &LsColors) -> Option<&Style> {97 self.style98 .get_or_init(|| ls_colors.style_for(self).cloned())99 .as_ref()100 }101}102103impl PartialEq for DirEntry {104 #[inline]
50 unmodified lines
modified:src/output.rs+2 added-2 removed
88 unmodified lines
89 .unwrap_or_default();90 write!(stdout, "{}", style.paint(parent_str))?;91 }9293 let style = ls_colors94 .style_for(entry)93 let style = entry94 .style(ls_colors)95 .map(Style::to_ansi_term_style)96 .unwrap_or_default();97 write!(stdout, "{}", style.paint(&path_str[offset..]))?;98
62 unmodified lines
modified:src/walk.rs+7 added
533 unmodified lines
534 return ignore::WalkState::Continue;535 }536 }537538 if config.is_printing() {539 if let Some(ls_colors) = &config.ls_colors {540 // Try to compute colors in parallel541 entry.style(ls_colors);542 }543 }544545 let send_result = tx_thread.send(WorkerResult::Entry(entry));546547 if send_result.is_err() {548 return ignore::WalkState::Quit;
11 unmodified lines
modified:CHANGELOG.md+1 added
17 unmodified lines
1819- No leading `./` prefix for non-interactive results, see above.20- fd can now avoid `stat` syscalls even when colorizing paths, as long as the color scheme doesn't21 require metadata, see #1148 (@tavianator)22- fd now colorizes paths in parallel, significantly improving performance, see #1148 (@tavianator)2324## Other2526- Added link back to GitHub in man page and `--help` text, see #1086 (@scottchiefbaker)
593 unmodified lines