Forráskód Böngészése

move zeros to constants module

Thomas Waldmann 4 éve
szülő
commit
be257728ca
3 módosított fájl, 6 hozzáadás és 4 törlés
  1. 1 1
      src/borg/archive.py
  2. 1 3
      src/borg/chunker.pyx
  3. 4 0
      src/borg/constants.py

+ 1 - 1
src/borg/archive.py

@@ -19,7 +19,7 @@ from .logger import create_logger
 logger = create_logger()
 
 from . import xattr
-from .chunker import get_chunker, Chunk, cached_hash, zeros
+from .chunker import get_chunker, Chunk, cached_hash
 from .cache import ChunkListEntry
 from .crypto.key import key_factory
 from .compress import Compressor, CompressionSpec

+ 1 - 3
src/borg/chunker.pyx

@@ -6,7 +6,7 @@ import errno
 import os
 from collections import namedtuple
 
-from .constants import CH_DATA, CH_ALLOC, CH_HOLE, MAX_DATA_SIZE
+from .constants import CH_DATA, CH_ALLOC, CH_HOLE, MAX_DATA_SIZE, zeros
 from .lrucache import LRUCache
 
 from libc.stdlib cimport free
@@ -53,8 +53,6 @@ def Chunk(data, **meta):
     return _Chunk(meta, data)
 
 
-zeros = bytes(MAX_DATA_SIZE)
-
 # remember a few recently used all-zero chunk hashes in this mapping.
 # (hash_func, chunk_length) -> chunk_hash
 # we play safe and have the hash_func in the mapping key, in case we

+ 4 - 0
src/borg/constants.py

@@ -45,6 +45,10 @@ assert MAX_OBJECT_SIZE == 20 * 1024 * 1024
 # repo config max_segment_size value must be below this limit to stay within uint32 offsets:
 MAX_SEGMENT_SIZE_LIMIT = 2 ** 32 - MAX_OBJECT_SIZE
 
+# have one all-zero bytes object
+# we use it at all places where we need to detect or create all-zero buffers
+zeros = bytes(MAX_DATA_SIZE)
+
 # borg.remote read() buffer size
 BUFSIZE = 10 * 1024 * 1024