]> arthur.barton.de Git - bup.git/commitdiff
Fix some list comprehensions that I thought were generator comprehensions.
authorAvery Pennarun <apenwarr@gmail.com>
Tue, 9 Feb 2010 00:26:38 +0000 (19:26 -0500)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 9 Feb 2010 00:26:38 +0000 (19:26 -0500)
Apparently [x for x in whatever] yields a list, not an iterator, which means
two things:
  - it might use more memory than I thought
  - you definitely don't need to write list([...]) since it's already a
    list.

Clean up a few of these.  You learn something new every day.

cmd-index.py
cmd-midx.py
git.py
helpers.py

index fbbc890fe279c37fbb787abd8bd023b708ddab78..ac7e47a007b08692211e07d5b4ffc6c66656eb2d 100755 (executable)
@@ -5,10 +5,10 @@ from helpers import *
 
 
 def _simplify_iter(iters):
-    total = sum([len(it) for it in iters])
-    l = list([iter(it) for it in iters])
+    total = sum(len(it) for it in iters)
+    l = [iter(it) for it in iters]
     del iters
-    l = list([(next(it),it) for it in l])
+    l = [(next(it),it) for it in l]
     l = filter(lambda x: x[0], l)
     count = 0
     while l:
index b421e0ec419f88205759914eaa9beff85315a72e..b63e20168011344fda34e07c5cdbbb3cf49e2abf 100755 (executable)
@@ -55,7 +55,7 @@ def do_midx(outdir, outfilename, infilenames):
     for e in merge(inp, bits, table):
         f.write(e)
         
-    f.write('\0'.join([os.path.basename(p) for p in infilenames]))
+    f.write('\0'.join(os.path.basename(p) for p in infilenames))
 
     f.seek(12)
     f.write(struct.pack('!%dI' % entries, *table))
diff --git a/git.py b/git.py
index 9d7bad5e6aee1f01941b64ee5a99351a0edd6f6f..444752fd10d1b32b5b34041e00522b5985e87c10 100644 (file)
--- a/git.py
+++ b/git.py
@@ -234,7 +234,7 @@ class MultiPackIndex:
         if forget_packs:
             self.packs = []
         skip_midx = skip_midx or ignore_midx
-        d = dict([(p.name, 1) for p in self.packs])
+        d = dict((p.name, 1) for p in self.packs)
         if os.path.exists(self.dir):
             if not skip_midx:
                 midxl = []
@@ -282,8 +282,8 @@ def _shalist_sort_key(ent):
 
 
 def idxmerge(idxlist):
-    total = sum([len(i) for i in idxlist])
-    iters = [iter(i) for i in idxlist]
+    total = sum(len(i) for i in idxlist)
+    iters = (iter(i) for i in idxlist)
     heap = [(next(it), it) for it in iters]
     heapq.heapify(heap)
     count = 0
index ac04a957ded08a90a52b34d886479a4b3e993ef8..d386185135d440f51347af85ac873ef1813c9a84 100644 (file)
@@ -42,7 +42,7 @@ def readpipe(argv):
 # But it's used in a couple of places, so let's put it here.
 def pathsplit(p):
     l = p.split('/')
-    l = list([i+'/' for i in l[:-1]]) + l[-1:]
+    l = [i+'/' for i in l[:-1]] + l[-1:]
     if l[-1] == '':
         l.pop()  # extra blank caused by terminating '/'
     return l