changeset 20292:8dc254198a8f

changectx: increase perf of walk function When running 'hg cat -r . <file>' it was doing an expensive ctx.walk(m) which applied the regex to every file in the manifest. This changes changectx.walk to iterate over just the files in the regex, if no other patterns are specified. This cuts hg cat time by 50% in our repo and probably benefits a few other commands as well.
author Durham Goode <durham@fb.com>
date Tue, 14 Jan 2014 13:49:19 -0800
parents 7d589d923b8a
children 2f6b3900be64
files mercurial/context.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Wed Jan 15 16:46:20 2014 -0800
+++ b/mercurial/context.py	Tue Jan 14 13:49:19 2014 -0800
@@ -410,6 +410,15 @@
         # for dirstate.walk, files=['.'] means "walk the whole tree".
         # follow that here, too
         fset.discard('.')
+
+        # avoid the entire walk if we're only looking for specific files
+        if fset and not match.anypats():
+            if util.all([fn in self for fn in fset]):
+                for fn in sorted(fset):
+                    if match(fn):
+                        yield fn
+                raise StopIteration
+
         for fn in self:
             if fn in fset:
                 # specified pattern is the exact name