Rev 3658: sum(map(len, foo))) is better than using += for one-off. in http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/btree
John Arbash Meinel
john at arbash-meinel.com
Thu Aug 21 20:57:05 BST 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.7-dev/btree
------------------------------------------------------------
revno: 3658
revision-id: john at arbash-meinel.com-20080821195703-ze7jwvq1r2rbgmr3
parent: john at arbash-meinel.com-20080821195353-1q7mrhcjqerr5rhh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: btree
timestamp: Thu 2008-08-21 14:57:03 -0500
message:
sum(map(len, foo))) is better than using += for one-off.
modified:
bzrlib/chunk_writer.py chunk_writer.py-20080630234519-6ggn4id17nipovny-1
-------------- next part --------------
=== modified file 'bzrlib/chunk_writer.py'
--- a/bzrlib/chunk_writer.py 2008-08-21 19:53:53 +0000
+++ b/bzrlib/chunk_writer.py 2008-08-21 19:57:03 +0000
@@ -125,21 +125,18 @@
"""
compressor = zlib.compressobj()
bytes_out = []
- bytes_out_len = 0
append = bytes_out.append
compress = compressor.compress
for accepted_bytes in self.bytes_in:
out = compress(accepted_bytes)
if out:
append(out)
- bytes_out_len += len(out)
if extra_bytes:
out = compress(extra_bytes)
out += compressor.flush(Z_SYNC_FLUSH)
if out:
append(out)
- bytes_out_len += len(out)
- return bytes_out, bytes_out_len, compressor
+ return bytes_out, compressor
def write(self, bytes):
"""Write some bytes to the chunk.
@@ -190,18 +187,17 @@
# We are over budget, try to squeeze this in without any
# Z_SYNC_FLUSH calls
self.num_repack += 1
- (bytes_out, this_len,
- compressor) = self._recompress_all_bytes_in(bytes)
+ bytes_out, compressor = self._recompress_all_bytes_in(bytes)
+ this_len = sum(map(len, bytes_out))
if this_len + 10 > capacity:
# No way we can add anymore, we need to re-pack because our
# compressor is now out of sync.
# This seems to be rarely triggered over
# num_repack > _max_repack
- (bytes_out, this_len,
- compressor) = self._recompress_all_bytes_in()
+ bytes_out, compressor = self._recompress_all_bytes_in()
self.compressor = compressor
self.bytes_list = bytes_out
- self.bytes_out_len = this_len
+ self.bytes_out_len = sum(map(len, bytes_out))
self.unused_bytes = bytes
return True
else:
More information about the bazaar-commits
mailing list