1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-12 19:18:24 +02:00

cleanup: rename match_count to match_line_count

This commit is contained in:
Balaji Sivaraman 2018-02-20 21:00:02 +05:30 committed by Andrew Gallant
parent b006943c01
commit 96f73293c0
No known key found for this signature in database
GPG Key ID: B2E3A4923F8B0D44
3 changed files with 32 additions and 32 deletions

View File

@ -88,13 +88,13 @@ fn run_parallel(args: &Arc<Args>) -> Result<u64> {
let bufwtr = Arc::new(args.buffer_writer()); let bufwtr = Arc::new(args.buffer_writer());
let quiet_matched = args.quiet_matched(); let quiet_matched = args.quiet_matched();
let paths_searched = Arc::new(AtomicUsize::new(0)); 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(|| { args.walker_parallel().run(|| {
let args = Arc::clone(args); let args = Arc::clone(args);
let quiet_matched = quiet_matched.clone(); let quiet_matched = quiet_matched.clone();
let paths_searched = paths_searched.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 bufwtr = Arc::clone(&bufwtr);
let mut buf = bufwtr.buffer(); let mut buf = bufwtr.buffer();
let mut worker = args.worker(); let mut worker = args.worker();
@ -125,7 +125,7 @@ fn run_parallel(args: &Arc<Args>) -> Result<u64> {
} else { } else {
worker.run(&mut printer, Work::DirEntry(dent)) 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) { if quiet_matched.set_match(count > 0) {
return Quit; return Quit;
} }
@ -141,7 +141,7 @@ fn run_parallel(args: &Arc<Args>) -> Result<u64> {
eprint_nothing_searched(); 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<Args>) -> Result<u64> { fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
@ -149,7 +149,7 @@ fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
let mut stdout = stdout.lock(); let mut stdout = stdout.lock();
let mut worker = args.worker(); let mut worker = args.worker();
let mut paths_searched: u64 = 0; let mut paths_searched: u64 = 0;
let mut match_count = 0; let mut match_line_count = 0;
for result in args.walker() { for result in args.walker() {
let dent = match get_or_log_dir_entry( let dent = match get_or_log_dir_entry(
result, result,
@ -161,7 +161,7 @@ fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
Some(dent) => dent, Some(dent) => dent,
}; };
let mut printer = args.printer(&mut stdout); let mut printer = args.printer(&mut stdout);
if match_count > 0 { if match_line_count > 0 {
if args.quiet() { if args.quiet() {
break; break;
} }
@ -170,7 +170,7 @@ fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
} }
} }
paths_searched += 1; paths_searched += 1;
match_count += match_line_count +=
if dent.is_stdin() { if dent.is_stdin() {
worker.run(&mut printer, Work::Stdin) worker.run(&mut printer, Work::Stdin)
} else { } else {
@ -182,7 +182,7 @@ fn run_one_thread(args: &Arc<Args>) -> Result<u64> {
eprint_nothing_searched(); eprint_nothing_searched();
} }
} }
Ok(match_count) Ok(match_line_count)
} }
fn run_files_parallel(args: Arc<Args>) -> Result<u64> { fn run_files_parallel(args: Arc<Args>) -> Result<u64> {

View File

@ -21,7 +21,7 @@ pub struct BufferSearcher<'a, W: 'a> {
grep: &'a Grep, grep: &'a Grep,
path: &'a Path, path: &'a Path,
buf: &'a [u8], buf: &'a [u8],
match_count: u64, match_line_count: u64,
line_count: Option<u64>, line_count: Option<u64>,
byte_offset: Option<u64>, byte_offset: Option<u64>,
last_line: usize, last_line: usize,
@ -40,7 +40,7 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> {
grep: grep, grep: grep,
path: path, path: path,
buf: buf, buf: buf,
match_count: 0, match_line_count: 0,
line_count: None, line_count: None,
byte_offset: None, byte_offset: None,
last_line: 0, last_line: 0,
@ -130,7 +130,7 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> {
return 0; return 0;
} }
self.match_count = 0; self.match_line_count = 0;
self.line_count = if self.opts.line_number { Some(0) } else { None }; self.line_count = if self.opts.line_number { Some(0) } else { None };
// The memory map searcher uses one contiguous block of bytes, so the // The memory map searcher uses one contiguous block of bytes, so the
// offsets given the printer are sufficient to compute the byte offset. // 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()); self.print_match(m.start(), m.end());
} }
last_end = m.end(); last_end = m.end();
if self.opts.terminate(self.match_count) { if self.opts.terminate(self.match_line_count) {
break; 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(); let upto = self.buf.len();
self.print_inverted_matches(last_end, upto); self.print_inverted_matches(last_end, upto);
} }
if self.opts.count && self.match_count > 0 { if self.opts.count && self.match_line_count > 0 {
self.printer.path_count(self.path, self.match_count); 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); 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.printer.path(self.path);
} }
self.match_count self.match_line_count
} }
#[inline(always)] #[inline(always)]
pub fn print_match(&mut self, start: usize, end: usize) { pub fn print_match(&mut self, start: usize, end: usize) {
self.match_count += 1; self.match_line_count += 1;
if self.opts.skip_matches() { if self.opts.skip_matches() {
return; return;
} }
@ -181,7 +181,7 @@ impl<'a, W: WriteColor> BufferSearcher<'a, W> {
debug_assert!(self.opts.invert_match); debug_assert!(self.opts.invert_match);
let mut it = IterLines::new(self.opts.eol, start); let mut it = IterLines::new(self.opts.eol, start);
while let Some((s, e)) = it.next(&self.buf[..end]) { 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; return;
} }
self.print_match(s, e); self.print_match(s, e);

View File

@ -67,7 +67,7 @@ pub struct Searcher<'a, R, W: 'a> {
grep: &'a Grep, grep: &'a Grep,
path: &'a Path, path: &'a Path,
haystack: R, haystack: R,
match_count: u64, match_line_count: u64,
line_count: Option<u64>, line_count: Option<u64>,
byte_offset: Option<u64>, byte_offset: Option<u64>,
last_match: Match, last_match: Match,
@ -127,12 +127,12 @@ impl Options {
self.files_with_matches || self.files_without_matches || self.quiet self.files_with_matches || self.files_without_matches || self.quiet
} }
/// Returns true if the search should terminate based on the match count. /// Returns true if the search should terminate based on the match line count.
pub fn terminate(&self, match_count: u64) -> bool { pub fn terminate(&self, match_line_count: u64) -> bool {
if match_count > 0 && self.stop_after_first_match() { if match_line_count > 0 && self.stop_after_first_match() {
return true; 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; return true;
} }
false false
@ -166,7 +166,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
grep: grep, grep: grep,
path: path, path: path,
haystack: haystack, haystack: haystack,
match_count: 0, match_line_count: 0,
line_count: None, line_count: None,
byte_offset: None, byte_offset: None,
last_match: Match::default(), last_match: Match::default(),
@ -271,7 +271,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
#[inline(never)] #[inline(never)]
pub fn run(mut self) -> Result<u64, Error> { pub fn run(mut self) -> Result<u64, Error> {
self.inp.reset(); 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.line_count = if self.opts.line_number { Some(0) } else { None };
self.byte_offset = if self.opts.byte_offset { Some(0) } else { None }; self.byte_offset = if self.opts.byte_offset { Some(0) } else { None };
self.last_match = Match::default(); 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); self.print_after_context(upto);
} }
} }
if self.match_count > 0 { if self.match_line_count > 0 {
if self.opts.count { 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 { } else if self.opts.files_with_matches {
self.printer.path(self.path); self.printer.path(self.path);
} }
} else if self.opts.files_without_matches { } else if self.opts.files_without_matches {
self.printer.path(self.path); self.printer.path(self.path);
} }
Ok(self.match_count) Ok(self.match_line_count)
} }
#[inline(always)] #[inline(always)]
fn terminate(&self) -> bool { fn terminate(&self) -> bool {
self.opts.terminate(self.match_count) self.opts.terminate(self.match_line_count)
} }
#[inline(always)] #[inline(always)]
@ -427,7 +427,7 @@ impl<'a, R: io::Read, W: WriteColor> Searcher<'a, R, W> {
#[inline(always)] #[inline(always)]
fn print_match(&mut self, start: usize, end: usize) { fn print_match(&mut self, start: usize, end: usize) {
self.match_count += 1; self.match_line_count += 1;
if self.opts.skip_matches() { if self.opts.skip_matches() {
return; return;
} }