diff --git a/src/internal.rs b/src/internal.rs index 88fd1c710..c694045e0 100644 --- a/src/internal.rs +++ b/src/internal.rs @@ -101,6 +101,9 @@ fn expr_has_uppercase_char(expr: &Expr) -> bool { } } +/// Maximum size of the output buffer before flushing results to the console +pub const MAX_BUFFER_LENGTH: usize = 1000; + /// Exit code representing a general error pub const EXITCODE_ERROR: i32 = 1; diff --git a/src/walk.rs b/src/walk.rs index 584fd5e20..f30226acd 100644 --- a/src/walk.rs +++ b/src/walk.rs @@ -10,7 +10,7 @@ extern crate ctrlc; use exec; use fshelper; -use internal::{error, FdOptions, EXITCODE_SIGINT}; +use internal::{error, FdOptions, EXITCODE_SIGINT, MAX_BUFFER_LENGTH}; use output; use std::process; @@ -147,8 +147,10 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc, config: Arc) { ReceiverMode::Buffering => { buffer.push(value); - // Have we reached the maximum time? - if time::Instant::now() - start > max_buffer_time { + // Have we reached the maximum buffer size or maximum buffering time? + if buffer.len() > MAX_BUFFER_LENGTH + || time::Instant::now() - start > max_buffer_time + { // Flush the buffer for v in &buffer { output::print_entry(v, &rx_config, &receiver_wtq);