Rev 3826: Serialize the common lookup prefix, so that we don't have to compute it during deserialization. in http://bzr.arbash-meinel.com/branches/bzr/brisbane/hack
John Arbash Meinel
john at arbash-meinel.com
Wed Dec 24 19:25:16 GMT 2008
At http://bzr.arbash-meinel.com/branches/bzr/brisbane/hack
------------------------------------------------------------
revno: 3826
revision-id: john at arbash-meinel.com-20081224192457-80lac61kjh2lin23
parent: john at arbash-meinel.com-20081224180554-7qe1csn2l400xz2h
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: hack
timestamp: Wed 2008-12-24 13:24:57 -0600
message:
Serialize the common lookup prefix, so that we don't have to compute it during deserialization.
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py 2008-12-24 17:20:36 +0000
+++ b/bzrlib/chk_map.py 2008-12-24 19:24:57 +0000
@@ -511,10 +511,15 @@
prefix_len = len(self._common_serialised_prefix)
# prefix_len = 0
bytes_for_items = (self._raw_size - (prefix_len * self._len))
+ if self._lookup_prefix is None:
+ lookup_len = 0
+ else:
+ lookup_len = len(self._lookup_prefix)
return (9 # 'chkleaf:\n'
+ len(str(self._maximum_size)) + 1
+ len(str(self._key_width)) + 1
+ len(str(self._len)) + 1
+ + lookup_len + 1
+ prefix_len + 1
+ bytes_for_items)
@@ -534,10 +539,13 @@
maximum_size = int(lines[1])
width = int(lines[2])
length = int(lines[3])
- pos = 5
- prefix = lines[4]
+ lookup_prefix = lines[4]
+ assert lookup_prefix[-1] == '\n'
+ lookup_prefix = lookup_prefix[:-1] # Remove the trailing newline
+ prefix = lines[5]
assert prefix[-1] == '\n'
prefix = prefix[:-1] # Remove the trailing newline
+ pos = 6
while pos < len(lines):
elements = (prefix + lines[pos]).split('\x00')
assert len(elements) == width + 1
@@ -560,10 +568,18 @@
result._key = key
result._orig_key = key
result._key_width = width
- result._raw_size = (sum(map(len, lines[5:])) # the length of the suffix
+ result._raw_size = (sum(map(len, lines[6:])) # the length of the suffix
+ (length)*(len(prefix))) # prefix
- result._compute_lookup_prefix()
- result._compute_serialised_prefix()
+ if result._len == 0:
+ result._common_serialised_prefix = None
+ result._lookup_prefix = None
+ else:
+ result._common_serialised_prefix = prefix
+ result._lookup_prefix = lookup_prefix
+ # result._compute_lookup_prefix()
+ # assert result._lookup_prefix == lookup_prefix
+ # result._compute_serialised_prefix()
+ # assert result._common_serialised_prefix == prefix
if len(bytes) != result._current_size():
import pdb; pdb.set_trace()
assert len(bytes) == result._current_size()
@@ -684,6 +700,10 @@
lines.append("%d\n" % self._maximum_size)
lines.append("%d\n" % self._key_width)
lines.append("%d\n" % self._len)
+ if self._lookup_prefix is None:
+ lines.append('\n')
+ else:
+ lines.append('%s\n' % (self._lookup_prefix,))
if self._common_serialised_prefix is None:
lines.append('\n')
else:
@@ -691,6 +711,7 @@
# prefix_len = 0
lines.append('%s\n' % (self._common_serialised_prefix,))
prefix_len = len(self._common_serialised_prefix)
+
for key, value in sorted(self._items.items()):
value_lines = osutils.chunks_to_lines([value + '\n'])
serialized = "%s\x00%s\n" % (self._serialise_key(key),
@@ -864,6 +885,7 @@
result._raw_size = None # len(bytes)
result._node_width = len(prefix)
result._compute_lookup_prefix()
+ assert result._lookup_prefix == common_prefix
return result
def iteritems(self, store, key_filter=None):
More information about the bazaar-commits
mailing list