From 870f41469025fc6e4ba0d16a4e634c79c571c50d Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Thu, 20 Nov 2025 01:35:03 +0100 Subject: [PATCH] buzhash/buzhash64: initialise all-zero memory more efficiently --- src/borg/chunkers/buzhash.pyx | 6 +++--- src/borg/chunkers/buzhash64.pyx | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/borg/chunkers/buzhash.pyx b/src/borg/chunkers/buzhash.pyx index 4453d511d..627d5ba62 100644 --- a/src/borg/chunkers/buzhash.pyx +++ b/src/borg/chunkers/buzhash.pyx @@ -7,7 +7,7 @@ import time from cpython.bytes cimport PyBytes_AsString from libc.stdint cimport uint8_t, uint32_t from libc.stdlib cimport malloc, free -from libc.string cimport memcpy, memmove +from libc.string cimport memcpy, memmove, memset from ..constants import CH_DATA, CH_ALLOC, CH_HOLE, zeros from .reader import FileReader, Chunk @@ -199,8 +199,8 @@ cdef class Chunker: # Copy data from chunk to our buffer memcpy(self.data + self.position + self.remaining, PyBytes_AsString(chunk.data), n) else: - # For holes, fill with zeros - memcpy(self.data + self.position + self.remaining, PyBytes_AsString(zeros[:n]), n) + # For holes, fill with zeros using memset + memset(self.data + self.position + self.remaining, 0, n) self.remaining += n self.bytes_read += n diff --git a/src/borg/chunkers/buzhash64.pyx b/src/borg/chunkers/buzhash64.pyx index f16ddb3ef..c241e5845 100644 --- a/src/borg/chunkers/buzhash64.pyx +++ b/src/borg/chunkers/buzhash64.pyx @@ -8,7 +8,7 @@ import time from cpython.bytes cimport PyBytes_AsString from libc.stdint cimport uint8_t, uint64_t from libc.stdlib cimport malloc, free -from libc.string cimport memcpy, memmove +from libc.string cimport memcpy, memmove, memset from ..crypto.low_level import CSPRNG @@ -176,8 +176,8 @@ cdef class ChunkerBuzHash64: # Copy data from chunk to our buffer memcpy(self.data + self.position + self.remaining, PyBytes_AsString(chunk.data), n) else: - # For holes, fill with zeros - memcpy(self.data + self.position + self.remaining, PyBytes_AsString(zeros[:n]), n) + # For holes, fill with zeros using memset + memset(self.data + self.position + self.remaining, 0, n) self.remaining += n self.bytes_read += n