addremove: avoid fetching data again and again
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Mon, 08 Mar 2010 00:01:12 +0100
changeset 10608 87fce8c5e29d
parent 10607 f3ac9d6105ee
child 10609 5ee3faa7c563
addremove: avoid fetching data again and again
mercurial/cmdutil.py
--- a/mercurial/cmdutil.py	Mon Mar 08 00:00:03 2010 +0100
+++ b/mercurial/cmdutil.py	Mon Mar 08 00:01:12 2010 +0100
@@ -295,6 +295,12 @@
             continue
         fctx = ctx.filectx(r)
 
+        # lazily load text
+        @util.cachefunc
+        def data():
+            orig = fctx.data()
+            return orig, mdiff.splitnewlines(orig)
+
         def score(text):
             if not len(text):
                 return 0.0
@@ -302,14 +308,13 @@
                 return 1.0
             if threshold == 1.0:
                 return 0.0
-            orig = fctx.data()
+            orig, lines = data()
             # bdiff.blocks() returns blocks of matching lines
             # count the number of bytes in each
             equal = 0
-            alines = mdiff.splitnewlines(text)
             matches = bdiff.blocks(text, orig)
             for x1, x2, y1, y2 in matches:
-                for line in alines[x1:x2]:
+                for line in lines[y1:y2]:
                     equal += len(line)
 
             lengths = len(text) + len(orig)