manifest.add(): simplify with iterators and generator expressions
authorBenoit Boissinot <benoit.boissinot@ens-lyon.org>
Wed, 02 Sep 2009 20:18:35 +0200
changeset 9413 a5adf55ee533
parent 9412 3a78bbc57660
child 9414 65dc516363ee
manifest.add(): simplify with iterators and generator expressions
mercurial/manifest.py
--- a/mercurial/manifest.py	Sat Aug 29 00:30:03 2009 +0200
+++ b/mercurial/manifest.py	Wed Sep 02 20:18:35 2009 +0200
@@ -110,17 +110,13 @@
         def addlistdelta(addlist, x):
             # start from the bottom up
             # so changes to the offsets don't mess things up.
-            i = len(x)
-            while i > 0:
-                i -= 1
-                start = x[i][0]
-                end = x[i][1]
-                if x[i][2]:
-                    addlist[start:end] = array.array('c', x[i][2])
+            for start, end, content in reversed(x):
+                if content:
+                    addlist[start:end] = array.array('c', content)
                 else:
                     del addlist[start:end]
-            return "".join([struct.pack(">lll", d[0], d[1], len(d[2])) + d[2]
-                            for d in x ])
+            return "".join(struct.pack(">lll", start, end, len(content)) + content
+                           for start, end, content in x)
 
         def checkforbidden(l):
             for f in l: