Skip to content

Commit

Permalink
Introduce maximum output buffer size (#212)
Browse files Browse the repository at this point in the history
Closes #191
  • Loading branch information
sharkdp committed Jan 3, 2018
1 parent 39fb41f commit 32a34cf
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 5 additions & 3 deletions src/walk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -147,8 +147,10 @@ pub fn scan(path_vec: &[PathBuf], pattern: Arc<Regex>, config: Arc<FdOptions>) {
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);
Expand Down

0 comments on commit 32a34cf

Please sign in to comment.