Skip to content
Snippets Groups Projects
Commit aea6562a authored by mpm's avatar mpm
Browse files

Make compression more intelligent:

- we don't attempt to compress things under 44 bytes (empirical)
- we check whether larger objects actually compress
- we tag objects to indicate their compression
  NUL means uncompressed and starts with NUL
  x means gzipped and starts with x (handy)
  u means uncompressed, drop the u
parent 2c80f6f8
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,14 @@
def short(node): return hex(node[:4])
def compress(text):
return zlib.compress(text)
if not text: return text
if len(text) < 44:
if text[0] == '\0': return text
return 'u' + text
bin = zlib.compress(text)
if len(bin) > len(text):
if text[0] == '\0': return text
return 'u' + text
return bin
def decompress(bin):
......@@ -20,6 +28,11 @@
def decompress(bin):
return zlib.decompress(bin)
if not bin: return bin
t = bin[0]
if t == '\0': return bin
if t == 'x': return zlib.decompress(bin)
if t == 'u': return bin[1:]
raise "unknown compression type %s" % t
def hash(text, p1, p2):
l = [p1, p2]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment