From 4e3be1db5e73cb5a90f0a2865ccd961da7bc0661 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Fri, 8 Jan 2021 20:03:34 +0100 Subject: [PATCH] reuse zeros also in fixed-size chunker for all-zero chunk detection also: zeros.startswith() is faster --- src/borg/chunker.pyx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/borg/chunker.pyx b/src/borg/chunker.pyx index 1da811500..8c3a297ab 100644 --- a/src/borg/chunker.pyx +++ b/src/borg/chunker.pyx @@ -178,7 +178,7 @@ class ChunkerFixed: # should borg try to do sparse input processing? # whether it actually can be done depends on the input file being seekable. 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): """ @@ -233,7 +233,7 @@ class ChunkerFixed: # read block from the range data = dread(offset, wanted, fd, fh) got = len(data) - if data == self.zeros[:got]: + if zeros.startswith(data): data = None is_zero = True else: