~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-10-15 21:34:10 UTC
  • mto: This revision was merged to the branch mainline in revision 3791.
  • Revision ID: john@arbash-meinel.com-20081015213410-g19sy2rpgxcl2sew
Change the name to ChunkWriter.set_optimize()

Also allow it to be passed during __init__ and pass it in from
BTreeBuilder.

Show diffs side-by-side

added added

removed removed

Lines of Context:
93
93
    _repack_opts_for_speed = (0, 8)
94
94
    _repack_opts_for_size = (20, 0)
95
95
 
96
 
    def __init__(self, chunk_size, reserved=0):
 
96
    def __init__(self, chunk_size, reserved=0, optimize_for_size=False):
97
97
        """Create a ChunkWriter to write chunk_size chunks.
98
98
 
99
99
        :param chunk_size: The total byte count to emit at the end of the
113
113
        self.unused_bytes = None
114
114
        self.reserved_size = reserved
115
115
        # Default is to make building fast rather than compact
116
 
        self._max_repack, self._max_zsync = ChunkWriter._repack_opts_for_speed
117
 
 
118
 
    def optimize(self, for_size=True):
119
 
        """Change how we optimize our writes.
120
 
 
121
 
        :param for_size: If True, optimize for minimum space usage, otherwise
122
 
            optimize for fastest writing speed.
123
 
        :return: None
124
 
        """
125
 
        if for_size:
126
 
            opts = ChunkWriter._repack_opts_for_size
127
 
        else:
128
 
            opts = ChunkWriter._repack_opts_for_speed
129
 
        self._max_repack, self._max_zsync = opts
 
116
        self.set_optimize(for_size=optimize_for_size)
130
117
 
131
118
    def finish(self):
132
119
        """Finish the chunk.
158
145
            self.bytes_list.append("\x00" * nulls_needed)
159
146
        return self.bytes_list, self.unused_bytes, nulls_needed
160
147
 
 
148
    def set_optimize(self, for_size=True):
 
149
        """Change how we optimize our writes.
 
150
 
 
151
        :param for_size: If True, optimize for minimum space usage, otherwise
 
152
            optimize for fastest writing speed.
 
153
        :return: None
 
154
        """
 
155
        if for_size:
 
156
            opts = ChunkWriter._repack_opts_for_size
 
157
        else:
 
158
            opts = ChunkWriter._repack_opts_for_speed
 
159
        self._max_repack, self._max_zsync = opts
 
160
 
161
161
    def _recompress_all_bytes_in(self, extra_bytes=None):
162
162
        """Recompress the current bytes_in, and optionally more.
163
163