]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/hashsplit.py
Fix memory leak in *stat calls in _helpers.c
[bup.git] / lib / bup / hashsplit.py
index 3cbcfc981b4e1280604712b2b0ffe2fbeff9411e..4c903c1e1340e7bf1e18f1c2b99f96c0149e0dd1 100644 (file)
@@ -2,9 +2,11 @@
 from __future__ import absolute_import
 import io, math, os
 
-from bup import _helpers, helpers
+from bup import _helpers, compat, helpers
+from bup.compat import buffer, join_bytes
 from bup.helpers import sc_page_size
 
+
 _fmincore = getattr(helpers, 'fmincore', None)
 
 BLOB_MAX = 8192*4   # 8192 is the "typical" blob size for bupsplit
@@ -22,12 +24,12 @@ GIT_MODE_SYMLINK = 0o120000
 # be ok if we always only put() large amounts of data at a time.
 class Buf:
     def __init__(self):
-        self.data = ''
+        self.data = b''
         self.start = 0
 
     def put(self, s):
         if s:
-            self.data = buffer(self.data, self.start) + s
+            self.data = join_bytes(buffer(self.data, self.start), s)
             self.start = 0
             
     def peek(self, count):
@@ -37,7 +39,10 @@ class Buf:
         self.start += count
 
     def get(self, count):
-        v = buffer(self.data, self.start, count)
+        if count <= 256:
+            v = self.data[self.start : self.start + count]
+        else:
+            v = buffer(self.data, self.start, count)
         self.start += count
         return v