Rev 2980: Use the GraphIndex header to answer key_count queries rather than parsing the entire index unnecessarily. in http://people.ubuntu.com/~robertc/baz2.0/index

Robert Collins robertc at robertcollins.net
Mon Nov 12 23:44:05 GMT 2007


At http://people.ubuntu.com/~robertc/baz2.0/index

------------------------------------------------------------
revno: 2980
revision-id:robertc at robertcollins.net-20071112234354-suyfvrs72rogqw2f
parent: pqm at pqm.ubuntu.com-20071112195430-0xgqswqpc1j2pk2m
committer: Robert Collins <robertc at robertcollins.net>
branch nick: index
timestamp: Tue 2007-11-13 10:43:54 +1100
message:
  Use the GraphIndex header to answer key_count queries rather than parsing the entire index unnecessarily.
modified:
  bzrlib/index.py                index.py-20070712131115-lolkarso50vjr64s-1
=== modified file 'bzrlib/index.py'
--- a/bzrlib/index.py	2007-10-18 01:17:01 +0000
+++ b/bzrlib/index.py	2007-11-12 23:43:54 +0000
@@ -36,6 +36,7 @@
 """)
 from bzrlib import debug, errors
 
+_HEADER_READV = (0, 200)
 _OPTION_KEY_ELEMENTS = "key_elements="
 _OPTION_LEN = "len="
 _OPTION_NODE_REFS = "node_ref_lists="
@@ -555,8 +556,7 @@
         For GraphIndex the estimate is exact.
         """
         if self._key_count is None:
-            # really this should just read the prefix
-            self._buffer_all()
+            self._read_and_parse([_HEADER_READV])
         return self._key_count
 
     def _lookup_keys_via_location(self, location_keys):
@@ -612,7 +612,7 @@
                 readv_ranges.append((location, length))
         # read the header if needed
         if self._bisect_nodes is None:
-            readv_ranges.append((0, 200))
+            readv_ranges.append(_HEADER_READV)
         self._read_and_parse(readv_ranges)
         # generate results:
         #  - figure out <, >, missing, present



More information about the bazaar-commits mailing list