From 96f73293c0b734d91b55ad1e6940da0f706eed65 Mon Sep 17 00:00:00 2001 From: Balaji Sivaraman Date: Tue, 20 Feb 2018 21:00:02 +0530 Subject: [PATCH] cleanup: rename match_count to match_line_count --- src/main.rs | 16 ++++++++-------- src/search_buffer.rs | 24 ++++++++++++------------ src/search_stream.rs | 24 ++++++++++++------------ 3 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/main.rs b/src/main.rs index b3b192c1..bc064816 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,13 +88,13 @@ fn run_parallel(args: &Arc) -> Result { let bufwtr = Arc::new(args.buffer_writer()); let quiet_matched = args.quiet_matched(); let paths_searched = Arc::new(AtomicUsize::new(0)); - let match_count = Arc::new(AtomicUsize::new(0)); + let match_line_count = Arc::new(AtomicUsize::new(0)); args.walker_parallel().run(|| { let args = Arc::clone(args); let quiet_matched = quiet_matched.clone(); let paths_searched = paths_searched.clone(); - let match_count = match_count.clone(); + let match_line_count = match_line_count.clone(); let bufwtr = Arc::clone(&bufwtr); let mut buf = bufwtr.buffer(); let mut worker = args.worker(); @@ -125,7 +125,7 @@ fn run_parallel(args: &Arc) -> Result { } else { worker.run(&mut printer, Work::DirEntry(dent)) }; - match_count.fetch_add(count as usize, Ordering::SeqCst); + match_line_count.fetch_add(count as usize, Ordering::SeqCst); if quiet_matched.set_match(count > 0) { return Quit; } @@ -141,7 +141,7 @@ fn run_parallel(args: &Arc) -> Result { eprint_nothing_searched(); } } - Ok(match_count.load(Ordering::SeqCst) as u64) + Ok(match_line_count.load(Ordering::SeqCst) as u64) } fn run_one_thread(args: &Arc) -> Result { @@ -149,7 +149,7 @@ fn run_one_thread(args: &Arc) -> Result { let mut stdout = stdout.lock(); let mut worker = args.worker(); let mut paths_searched: u64 = 0; - let mut match_count = 0; + let mut match_line_count = 0; for result in args.walker() { let dent = match get_or_log_dir_entry( result, @@ -161,7 +161,7 @@ fn run_one_thread(args: &Arc) -> Result { Some(dent) => dent, }; let mut printer = args.printer(&mut stdout); - if match_count > 0 { + if match_line_count > 0 { if args.quiet() { break; } @@ -170,7 +170,7 @@ fn run_one_thread(args: &Arc) -> Result { } } paths_searched += 1; - match_count += + match_line_count += if dent.is_stdin() { worker.run(&mut printer, Work::Stdin) } else { @@ -182,7 +182,7 @@ fn run_one_thread(args: &Arc) -> Result { eprint_nothing_searched(); } } - Ok(match_count) + Ok(match_line_count) } fn run_files_parallel(args: Arc) -> Result { diff --git a/src/search_buffer.rs b/src/search_buffer.rs index fa446f78..59869a9b 100644 --- a/src/search_buffer.rs +++ b/src/search_buffer.rs @@ -21,7 +21,7 @@ pub struct BufferSearcher<'a, W: 'a> { grep: &'a Grep, path: &'a Path, buf: &'a [u8], - match_count: u64, + match_line_count: u64, line_count: Option, byte_offset: Option, last_line: usize, @@ -40,7 +40,7 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> { grep: grep, path: path, buf: buf, - match_count: 0, + match_line_count: 0, line_count: None, byte_offset: None, last_line: 0, @@ -130,7 +130,7 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> { return 0; } - self.match_count = 0; + self.match_line_count = 0; self.line_count = if self.opts.line_number { Some(0) } else { None }; // The memory map searcher uses one contiguous block of bytes, so the // offsets given the printer are sufficient to compute the byte offset. @@ -143,29 +143,29 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> { self.print_match(m.start(), m.end()); } last_end = m.end(); - if self.opts.terminate(self.match_count) { + if self.opts.terminate(self.match_line_count) { break; } } - if self.opts.invert_match && !self.opts.terminate(self.match_count) { + if self.opts.invert_match && !self.opts.terminate(self.match_line_count) { let upto = self.buf.len(); self.print_inverted_matches(last_end, upto); } - if self.opts.count && self.match_count > 0 { - self.printer.path_count(self.path, self.match_count); + if self.opts.count && self.match_line_count > 0 { + self.printer.path_count(self.path, self.match_line_count); } - if self.opts.files_with_matches && self.match_count > 0 { + if self.opts.files_with_matches && self.match_line_count > 0 { self.printer.path(self.path); } - if self.opts.files_without_matches && self.match_count == 0 { + if self.opts.files_without_matches && self.match_line_count == 0 { self.printer.path(self.path); } - self.match_count + self.match_line_count } #[inline(always)] pub fn print_match(&mut self, start: usize, end: usize) { - self.match_count += 1; + self.match_line_count += 1; if self.opts.skip_matches() { return; } @@ -181,7 +181,7 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> { debug_assert!(self.opts.invert_match); let mut it = IterLines::new(self.opts.eol, start); while let Some((s, e)) = it.next(&self.buf[..end]) { - if self.opts.terminate(self.match_count) { + if self.opts.terminate(self.match_line_count) { return; } self.print_match(s, e); diff --git a/src/search_stream.rs b/src/search_stream.rs index 3021f515..5ccb09b9 100644 --- a/src/search_stream.rs +++ b/src/search_stream.rs @@ -67,7 +67,7 @@ pub struct Searcher<'a, R, W: 'a> { grep: &'a Grep, path: &'a Path, haystack: R, - match_count: u64, + match_line_count: u64, line_count: Option, byte_offset: Option, last_match: Match, @@ -127,12 +127,12 @@ impl Options { self.files_with_matches || self.files_without_matches || self.quiet } - /// Returns true if the search should terminate based on the match count. - pub fn terminate(&self, match_count: u64) -> bool { - if match_count > 0 && self.stop_after_first_match() { + /// Returns true if the search should terminate based on the match line count. + pub fn terminate(&self, match_line_count: u64) -> bool { + if match_line_count > 0 && self.stop_after_first_match() { return true; } - if self.max_count.map_or(false, |max| match_count >= max) { + if self.max_count.map_or(false, |max| match_line_count >= max) { return true; } false @@ -166,7 +166,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> { grep: grep, path: path, haystack: haystack, - match_count: 0, + match_line_count: 0, line_count: None, byte_offset: None, last_match: Match::default(), @@ -271,7 +271,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> { #[inline(never)] pub fn run(mut self) -> Result { self.inp.reset(); - self.match_count = 0; + self.match_line_count = 0; self.line_count = if self.opts.line_number { Some(0) } else { None }; self.byte_offset = if self.opts.byte_offset { Some(0) } else { None }; self.last_match = Match::default(); @@ -323,21 +323,21 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> { self.print_after_context(upto); } } - if self.match_count > 0 { + if self.match_line_count > 0 { if self.opts.count { - self.printer.path_count(self.path, self.match_count); + self.printer.path_count(self.path, self.match_line_count); } else if self.opts.files_with_matches { self.printer.path(self.path); } } else if self.opts.files_without_matches { self.printer.path(self.path); } - Ok(self.match_count) + Ok(self.match_line_count) } #[inline(always)] fn terminate(&self) -> bool { - self.opts.terminate(self.match_count) + self.opts.terminate(self.match_line_count) } #[inline(always)] @@ -427,7 +427,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> { #[inline(always)] fn print_match(&mut self, start: usize, end: usize) { - self.match_count += 1; + self.match_line_count += 1; if self.opts.skip_matches() { return; }