From patchwork Sat Feb 15 10:59:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [4, of, 5, RESEND] grep: use "found" instead of "filerevmatches" examination for efficiency From: Katsunori FUJIWARA X-Patchwork-Id: 3670 Message-Id: <07301d80e333276ad9b1.1392461976@juju> To: mercurial-devel@selenic.com Date: Sat, 15 Feb 2014 19:59:36 +0900 # HG changeset patch # User FUJIWARA Katsunori # Date 1392461645 -32400 # Sat Feb 15 19:54:05 2014 +0900 # Node ID 07301d80e333276ad9b1c5da007e0084e745749e # Parent 34798e580fada8795f71cee5ccb755c4f55e7e7a 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. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -3239,7 +3239,6 @@ rev = ctx.rev() datefunc = ui.quiet and util.shortdate or util.datestr found = False - filerevmatches = {} @util.cachefunc def binary(): flog = getfile(fn) @@ -3262,10 +3261,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]