]> arthur.barton.de Git - bup.git/commitdiff
hashsplit: avoid cat_bytes() if possible
authorJohannes Berg <johannes@sipsolutions.net>
Tue, 28 Apr 2020 21:35:33 +0000 (23:35 +0200)
committerRob Browning <rlb@defaultvalue.org>
Sun, 21 Jun 2020 16:20:58 +0000 (11:20 -0500)
If our current buffer is empty, there's no need to cat_bytes()
it with the new buffer, we can just replace the empty one with
the new one. This saves the memcpy() in many cases. Especially
if the whole file was read in one chunk (by bumping up the read
size) this saves a lot of time.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
lib/bup/hashsplit.py

index 0ae6acdb669a624a58688e3bc760ba01d0a35ddd..01e11a67c6ea89884edb8fd6e1aa9373d0fa4b58 100644 (file)
@@ -29,7 +29,10 @@ class Buf:
         self.start = 0
 
     def put(self, s):
-        if s:
+        if not self.data:
+            self.data = s
+            self.start = 0
+        elif s:
             remaining = len(self.data) - self.start
             self.data = cat_bytes(self.data, self.start, remaining,
                                   s, 0, len(s))