Browse Source

reuse zeros also in fixed-size chunker for all-zero chunk detection

also: zeros.startswith() is faster
Thomas Waldmann 4 years ago
parent
commit
4e3be1db5e
1 changed files with 2 additions and 2 deletions
  1. 2 2
      src/borg/chunker.pyx

+ 2 - 2
src/borg/chunker.pyx

@@ -178,7 +178,7 @@ class ChunkerFixed:
         # should borg try to do sparse input processing?
         # should borg try to do sparse input processing?
         # whether it actually can be done depends on the input file being seekable.
         # whether it actually can be done depends on the input file being seekable.
         self.try_sparse = sparse and has_seek_hole
         self.try_sparse = sparse and has_seek_hole
-        self.zeros = memoryview(bytes(block_size))
+        assert block_size <= len(zeros)
 
 
     def chunkify(self, fd=None, fh=-1, fmap=None):
     def chunkify(self, fd=None, fh=-1, fmap=None):
         """
         """
@@ -233,7 +233,7 @@ class ChunkerFixed:
                     # read block from the range
                     # read block from the range
                     data = dread(offset, wanted, fd, fh)
                     data = dread(offset, wanted, fd, fh)
                     got = len(data)
                     got = len(data)
-                    if data == self.zeros[:got]:
+                    if zeros.startswith(data):
                         data = None
                         data = None
                         is_zero = True
                         is_zero = True
                     else:
                     else: