~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/chunk_writer.py

  • Committer: John Arbash Meinel
  • Date: 2008-08-21 19:57:03 UTC
  • mto: This revision was merged to the branch mainline in revision 3644.
  • Revision ID: john@arbash-meinel.com-20080821195703-ze7jwvq1r2rbgmr3
sum(map(len, foo))) is better than using += for one-off.

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
        """
126
126
        compressor = zlib.compressobj()
127
127
        bytes_out = []
128
 
        bytes_out_len = 0
129
128
        append = bytes_out.append
130
129
        compress = compressor.compress
131
130
        for accepted_bytes in self.bytes_in:
132
131
            out = compress(accepted_bytes)
133
132
            if out:
134
133
                append(out)
135
 
                bytes_out_len += len(out)
136
134
        if extra_bytes:
137
135
            out = compress(extra_bytes)
138
136
            out += compressor.flush(Z_SYNC_FLUSH)
139
137
            if out:
140
138
                append(out)
141
 
                bytes_out_len += len(out)
142
 
        return bytes_out, bytes_out_len, compressor
 
139
        return bytes_out, compressor
143
140
 
144
141
    def write(self, bytes):
145
142
        """Write some bytes to the chunk.
190
187
                # We are over budget, try to squeeze this in without any
191
188
                # Z_SYNC_FLUSH calls
192
189
                self.num_repack += 1
193
 
                (bytes_out, this_len,
194
 
                 compressor) = self._recompress_all_bytes_in(bytes)
 
190
                bytes_out, compressor = self._recompress_all_bytes_in(bytes)
 
191
                this_len = sum(map(len, bytes_out))
195
192
                if this_len + 10 > capacity:
196
193
                    # No way we can add anymore, we need to re-pack because our
197
194
                    # compressor is now out of sync.
198
195
                    # This seems to be rarely triggered over
199
196
                    #   num_repack > _max_repack
200
 
                    (bytes_out, this_len,
201
 
                     compressor) = self._recompress_all_bytes_in()
 
197
                    bytes_out, compressor = self._recompress_all_bytes_in()
202
198
                    self.compressor = compressor
203
199
                    self.bytes_list = bytes_out
204
 
                    self.bytes_out_len = this_len
 
200
                    self.bytes_out_len = sum(map(len, bytes_out))
205
201
                    self.unused_bytes = bytes
206
202
                    return True
207
203
                else: