~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/btree_index.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2008-11-12 05:49:02 UTC
  • mfrom: (3824.1.2 btree_no_size)
  • Revision ID: pqm@pqm.ubuntu.com-20081112054902-n6p0qrvl4cb26ij8
(jam) reading pack-names only issues a single read request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
881
881
            return
882
882
        start_of_leaves = self._row_offsets[-2]
883
883
        end_of_leaves = self._row_offsets[-1]
884
 
        needed_nodes = range(start_of_leaves, end_of_leaves)
 
884
        needed_offsets = range(start_of_leaves, end_of_leaves)
 
885
        if needed_offsets == [0]:
 
886
            # Special case when we only have a root node, as we have already
 
887
            # read everything
 
888
            nodes = [(0, self._root_node)]
 
889
        else:
 
890
            nodes = self._read_nodes(needed_offsets)
885
891
        # We iterate strictly in-order so that we can use this function
886
892
        # for spilling index builds to disk.
887
893
        if self.node_ref_lists:
888
 
            for _, node in self._read_nodes(needed_nodes):
 
894
            for _, node in nodes:
889
895
                for key, (value, refs) in sorted(node.keys.items()):
890
896
                    yield (self, key, value, refs)
891
897
        else:
892
 
            for _, node in self._read_nodes(needed_nodes):
 
898
            for _, node in nodes:
893
899
                for key, (value, refs) in sorted(node.keys.items()):
894
900
                    yield (self, key, value)
895
901
 
1246
1252
        :param nodes: The nodes to read. 0 - first node, 1 - second node etc.
1247
1253
        :return: None
1248
1254
        """
 
1255
        bytes = None
1249
1256
        ranges = []
1250
1257
        for index in nodes:
1251
1258
            offset = index * _PAGE_SIZE
1255
1262
                if self._size:
1256
1263
                    size = min(_PAGE_SIZE, self._size)
1257
1264
                else:
1258
 
                    stream = self._transport.get(self._name)
1259
 
                    start = stream.read(_PAGE_SIZE)
1260
 
                    # Avoid doing this again
1261
 
                    self._size = len(start)
1262
 
                    size = min(_PAGE_SIZE, self._size)
 
1265
                    # The only case where we don't know the size, is for very
 
1266
                    # small indexes. So we read the whole thing
 
1267
                    bytes = self._transport.get_bytes(self._name)
 
1268
                    self._size = len(bytes)
 
1269
                    ranges.append((0, len(bytes)))
 
1270
                    break
1263
1271
            else:
1264
1272
                if offset > self._size:
1265
1273
                    raise AssertionError('tried to read past the end'
1269
1277
            ranges.append((offset, size))
1270
1278
        if not ranges:
1271
1279
            return
1272
 
        if self._file is None:
 
1280
        if bytes:
 
1281
            data_ranges = [(offset, bytes[offset:offset+_PAGE_SIZE])
 
1282
                           for offset in xrange(0, len(bytes), _PAGE_SIZE)]
 
1283
        elif self._file is None:
1273
1284
            data_ranges = self._transport.readv(self._name, ranges)
1274
1285
        else:
1275
1286
            data_ranges = []