mercurial/cmdutil.py
changeset 10608 87fce8c5e29d
parent 10607 f3ac9d6105ee
child 10611 e764f24a45ee
--- 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)