mirror of
https://github.com/borgbackup/borg.git
synced 2025-02-25 07:23:28 +00:00
micro opt: callers shall provide a memoryview to .decompress()
if they would call with a bytes object, it would usually cause 1 object copy to remove the compression type bytes.
This commit is contained in:
parent
df23f3ed22
commit
154e5d87e7
2 changed files with 4 additions and 6 deletions
|
@ -90,8 +90,8 @@ cdef class CompressorBase:
|
|||
|
||||
def decompress(self, data):
|
||||
"""
|
||||
Decompress *data* (bytes) and return bytes result. The leading Compressor ID
|
||||
bytes need to be present.
|
||||
Decompress *data* (preferably a memoryview, bytes also acceptable) and return bytes result.
|
||||
The leading Compressor ID bytes need to be present.
|
||||
|
||||
Only handles input generated by _this_ Compressor - for a general purpose
|
||||
decompression method see *Compressor.decompress*.
|
||||
|
@ -489,8 +489,6 @@ class ObfuscateSize(CompressorBase):
|
|||
return super().compress(obfuscated_data) # add ID header
|
||||
|
||||
def decompress(self, data):
|
||||
if not isinstance(data, memoryview):
|
||||
data = memoryview(data)
|
||||
obfuscated_data = super().decompress(data) # remove obfuscator ID header
|
||||
compr_size = self.header_fmt.unpack(obfuscated_data[0:self.header_len])[0]
|
||||
compressed_data = obfuscated_data[self.header_len:self.header_len+compr_size]
|
||||
|
|
|
@ -355,7 +355,7 @@ def decrypt(self, id, data, decompress=True):
|
|||
raise IntegrityError(f"Chunk {bin_to_hex(id)}: Could not decrypt [{str(e)}]")
|
||||
if not decompress:
|
||||
return payload
|
||||
data = self.decompress(payload)
|
||||
data = self.decompress(memoryview(payload))
|
||||
self.assert_id(id, data)
|
||||
return data
|
||||
|
||||
|
@ -745,7 +745,7 @@ def decrypt(self, id, data, decompress=True):
|
|||
raise IntegrityError(f"Chunk {bin_to_hex(id)}: Could not decrypt [{str(e)}]")
|
||||
if not decompress:
|
||||
return payload
|
||||
data = self.decompress(payload)
|
||||
data = self.decompress(memoryview(payload))
|
||||
self.assert_id(id, data)
|
||||
return data
|
||||
|
||||
|
|
Loading…
Reference in a new issue