]> arthur.barton.de Git - bup.git/commitdiff
git.py: avoid repeated string-copying in tree_decode()
authorYung-Chin Oei <yungchin@yungchin.nl>
Wed, 26 Sep 2012 19:35:45 +0000 (20:35 +0100)
committerRob Browning <rlb@defaultvalue.org>
Fri, 28 Sep 2012 02:27:31 +0000 (21:27 -0500)
git.tree_decode showed bad perfomance when dealing with large trees,
because it required string-copying quadratically in the number of tree
elements. By removing unnecessary copying, performance is improved at
all tree sizes, and significantly so for larger trees.

The problem became particularly apparent in combination with another bug
in bup (patch for which forthcoming), that allowed trees to grow without
bound when backing up sparse files.

Reported-by: trebor <robert.rebstock@tempelhof-projekt.de>
Signed-off-by: Yung-Chin Oei <yungchin@yungchin.nl>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/git.py

index 8afe0b8e17ba5d7b21a494f2854dbbcd8431e594..3406edf7863bcd6fe858f607fef9fae62b0afb30 100644 (file)
@@ -155,13 +155,13 @@ def tree_decode(buf):
     """Generate a list of (mode,name,hash) from the git tree object in buf."""
     ofs = 0
     while ofs < len(buf):
-        z = buf[ofs:].find('\0')
-        assert(z > 0)
-        spl = buf[ofs:ofs+z].split(' ', 1)
+        z = buf.find('\0', ofs)
+        assert(z > ofs)
+        spl = buf[ofs:z].split(' ', 1)
         assert(len(spl) == 2)
         mode,name = spl
-        sha = buf[ofs+z+1:ofs+z+1+20]
-        ofs += z+1+20
+        sha = buf[z+1:z+1+20]
+        ofs = z+1+20
         yield (int(mode, 8), name, sha)