changeset 112:aea6562add6c

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
author mpm@selenic.com
date Fri, 20 May 2005 17:31:12 -0800
parents 2c80f6f8fc08
children 1918852a67a8
files mercurial/revlog.py
diffstat 1 files changed, 15 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/revlog.py	Fri May 20 17:28:09 2005 -0800
+++ b/mercurial/revlog.py	Fri May 20 17:31:12 2005 -0800
@@ -16,10 +16,23 @@
 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):
-    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]