Skip to content
Myr

Refactor: use some nice Rust methods in buffering code

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

authored by Niklas Mohrin · committed by David Peter · parent 45a8645 · Browse files · 1 file+12 added−15 removed
This commit

State

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

Diff stats

1 file+12 added−15 removed

  • other:+12 added−15 removed

1 file+12 added−15 removed

modified:src/walk.rs+12 added-15 removed
38 unmodified lines
39}4041/// Maximum size of the output buffer before flushing results to the console42pub const MAX_BUFFER_LENGTH: usize = 1000;43/// Default duration until output buffering switches to streaming.44pub const DEFAULT_MAX_BUFFER_TIME: time::Duration = time::Duration::from_millis(100);4546/// Recursively scan the given search path for files / pathnames matching the pattern.47///48/// If the `--exec` argument was supplied, this will create a thread pool for executing
172 unmodified lines
221 // Start in buffering mode222 let mut mode = ReceiverMode::Buffering;223224 // Maximum time to wait before we start streaming to the console.223 let max_buffer_time = config224 .max_buffer_time225 .unwrap_or_else(|| time::Duration::from_millis(100));225 let max_buffer_time = config.max_buffer_time.unwrap_or(DEFAULT_MAX_BUFFER_TIME);226227 let stdout = io::stdout();228 let mut stdout = stdout.lock();229
11 unmodified lines
241 buffer.push(value);242243 // Have we reached the maximum buffer size or maximum buffering time?244 if buffer.len() > MAX_BUFFER_LENGTH245 || time::Instant::now() - start > max_buffer_time245 || start.elapsed() > max_buffer_time246 {247 // Flush the buffer248 for v in &buffer {249 output::print_entry(
14 unmodified lines
264 }265 }266267 num_results += 1;268 if let Some(max_results) = config.max_results {269 if num_results >= max_results {270 break;271 }272 }273 }274 WorkerResult::Error(err) => {275 if show_filesystem_errors {276 print_error(err.to_string());277 }278 }279 }275276 if let Some(max_results) = config.max_results {277 if num_results >= max_results {278 break;279 }280 }280 }281282 // If we have finished fast enough (faster than max_buffer_time), we haven't streamed283 // anything to the console, yet. In this case, sort the results and print them:285 if !buffer.is_empty() {286 buffer.sort();287 for value in buffer {288 output::print_entry(&mut stdout, &value, &config, &wants_to_quit);284 buffer.sort();285 for value in buffer {286 output::print_entry(&mut stdout, &value, &config, &wants_to_quit);289 }287 }288289 if config.quiet {290 ExitCode::HasResults(false)
209 unmodified lines