Patchwork [4,of,5] grep: use "found" instead of "filerevmatches" examination for efficiency

login
register
mail settings
Submitter Katsunori FUJIWARA
Date Jan. 18, 2014, 3:24 p.m.
Message ID <3415a8717a17a5161df8.1390058641@vm-debian.dzone.foozy.private>
Download mbox | patch
Permalink /patch/3383/
State Superseded
Headers show

Comments

Katsunori FUJIWARA - Jan. 18, 2014, 3:24 p.m.
# HG changeset patch
# User FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
# Date 1390058567 -32400
#      Sun Jan 19 00:22:47 2014 +0900
# Node ID 3415a8717a17a5161df851510dbbfdacc3247d3a
# Parent  2f2ef51e1f5ef435fee4f618bd2db791531b6627
grep: use "found" instead of "filerevmatches" examination for efficiency

Before this patch, internal function "display()" of "hg grep" stores
whether matching is already found or not into the dictionary
"filerevmatches" by "(fn, rev)" tuple as the key.

But this is redundant, because:

  - "filerevmatches" is local variable of "display()", so each
    "display()" invocations don't affect others

  - both "fn" and "rev" (gotten from "ctx" argument) are never changed
    in each "display()" invocations

Then, "filerevmatches" should have only one entry at most, and "(fn,
rev) in filerevmatches" should be equal to "found".

This patch uses "found" instead of "filerevmatches" examination for
efficiency.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3230,7 +3230,6 @@ 
         rev = ctx.rev()
         datefunc = ui.quiet and util.shortdate or util.datestr
         found = False
-        filerevmatches = {}
         @util.cachefunc
         def binary():
             flog = getfile(fn)
@@ -3253,10 +3252,8 @@ 
             if opts.get('date'):
                 cols.append((datefunc(ctx.date()), 'grep.date'))
             if opts.get('files_with_matches'):
-                c = (fn, rev)
-                if c in filerevmatches:
+                if found:
                     continue
-                filerevmatches[c] = 1
             else:
                 before = l.line[:l.colstart]
                 match = l.line[l.colstart:l.colend]