# HG changeset patch # User Benoit Boissinot # Date 1268002872 -3600 # Node ID 87fce8c5e29d2eae3694fb70230737cc5c6e8d14 # Parent f3ac9d6105ee1bfeb223feee4b2830a99818df4a addremove: avoid fetching data again and again diff -r f3ac9d6105ee -r 87fce8c5e29d 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)