summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndrew Gallant <jamslam@gmail.com>2018-06-23 20:17:29 -0400
committerAndrew Gallant <jamslam@gmail.com>2018-06-23 20:49:05 -0400
commitcd6c1909674648f13d9de16aa7413ea7ed240e49 (patch)
tree1fa26c3cd2c3bdbb85201b34297f011424401ba9 /src
parentd5139228e5787b9ec0ea8209e64d3b878ab72309 (diff)
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
Diffstat (limited to 'src')
-rw-r--r--src/args.rs9
-rw-r--r--src/main.rs12
2 files changed, 11 insertions, 10 deletions
diff --git a/src/args.rs b/src/args.rs
index 0c231d0f..e410cd7c 100644
--- a/src/args.rs
+++ b/src/args.rs
@@ -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.
diff --git a/src/main.rs b/src/main.rs
index e374338b..6f010135 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -165,8 +165,7 @@ fn run_parallel(args: &Arc<Args>) -> Result<u64> {
fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
let start_time = Instant::now();
- let stdout = args.stdout();
- let mut stdout = stdout.lock();
+ let mut stdout = args.stdout();
let mut worker = args.worker();
let mut paths_searched: u64 = 0;
let mut match_line_count = 0;
@@ -223,8 +222,7 @@ fn run_files_parallel(args: Arc<Args>) -> Result<u64> {
let print_args = Arc::clone(&args);
let (tx, rx) = mpsc::channel::<ignore::DirEntry>();
let print_thread = thread::spawn(move || {
- let stdout = print_args.stdout();
- let mut printer = print_args.printer(stdout.lock());
+ let mut printer = print_args.printer(print_args.stdout());
let mut file_count = 0;
for dent in rx.iter() {
if !print_args.quiet() {
@@ -254,8 +252,7 @@ fn run_files_parallel(args: Arc<Args>) -> Result<u64> {
}
fn run_files_one_thread(args: &Arc<Args>) -> Result<u64> {
- let stdout = args.stdout();
- let mut printer = args.printer(stdout.lock());
+ let mut printer = args.printer(args.stdout());
let mut file_count = 0;
for result in args.walker() {
let dent = match get_or_log_dir_entry(
@@ -277,8 +274,7 @@ fn run_files_one_thread(args: &Arc<Args>) -> Result<u64> {
}
fn run_types(args: &Arc<Args>) -> Result<u64> {
- let stdout = args.stdout();
- let mut printer = args.printer(stdout.lock());
+ let mut printer = args.printer(args.stdout());
let mut ty_count = 0;
for def in args.type_defs() {
printer.type_def(def);