ripgrep: use new BufferedStandardStream from termcolor

Specifically, this will use a buffered writer when not printing to a tty.
This fixes a long standing performance regression where ripgrep would
slow down dramatically if it needed to report a lot of matches.

Fixes #955
This commit is contained in:
Andrew Gallant
2018-06-23 20:17:29 -04:00
parent d5139228e5
commit cd6c190967
2 changed files with 11 additions and 10 deletions

View File

@@ -228,8 +228,13 @@ impl Args {
}
/// Create a new writer for single-threaded searching with color support.
pub fn stdout(&self) -> termcolor::StandardStream {
termcolor::StandardStream::stdout(self.color_choice)
pub fn stdout(&self) -> Box<termcolor::WriteColor> {
if atty::is(atty::Stream::Stdout) {
Box::new(termcolor::StandardStream::stdout(self.color_choice))
} else {
Box::new(
termcolor::BufferedStandardStream::stdout(self.color_choice))
}
}
/// Returns a handle to stdout for filtering search.