Optimize annotate a bit
authormpm@selenic.com
Wed, 22 Jun 2005 12:14:44 -0800
changeset 436 6aeb4fee51f6
parent 435 e731d25ddab2
child 437 5b38a5af4019
Optimize annotate a bit -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Optimize annotate a bit Keep the original text around so we don't need to rejoin it Use slice insert-in-place rather than += to construct new lists Construct the decorated list with list multiply rather than comprehension manifest hash: 8c0effb9777750d524d71ad3a2eade3c6ddd579e -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.0 (GNU/Linux) iD8DBQFCuca0ywK+sNU5EO8RAtvQAJwOViomGCtlZx/R76i8/CZGvGPqUwCfdybd nRUv1854GjzCbfygzXfeIes= =6Q+E -----END PGP SIGNATURE-----
mercurial/hg.py
--- a/mercurial/hg.py	Wed Jun 22 11:31:24 2005 -0800
+++ b/mercurial/hg.py	Wed Jun 22 12:14:44 2005 -0800
@@ -63,19 +63,16 @@
     def annotate(self, node):
 
         def decorate(text, rev):
-            return [(rev, l) for l in text.splitlines(1)]
-
-        def strip(annotation):
-            return "".join([e[1] for e in annotation])
+            return ([rev] * len(text.splitlines()), text)
 
         def pair(parent, child):
             new = []
             lb = 0
-            for a1, a2, b1, b2 in bdiff.blocks(strip(parent), strip(child)):
-                new += child[lb:b1]
-                new += parent[a1:a2]
+            for a1, a2, b1, b2 in bdiff.blocks(parent[1], child[1]):
+                new[lb:] = child[0][lb:b1]
+                new[b1:] = parent[0][a1:a2]
                 lb = b2
-            return new
+            return (new, child[1])
 
         # find all ancestors
         needed = {node:1}
@@ -108,7 +105,7 @@
                         del hist[p]
             hist[n] = curr
 
-        return hist[n]
+        return zip(hist[n][0], hist[n][1].splitlines(1))
 
 class manifest(revlog):
     def __init__(self, opener):