Rev 2850: Merge dirstate lookup cache. in http://people.ubuntu.com/~robertc/baz2.0/repository
Robert Collins
robertc at robertcollins.net
Mon Oct 22 06:42:27 BST 2007
At http://people.ubuntu.com/~robertc/baz2.0/repository
------------------------------------------------------------
revno: 2850
revision-id:robertc at robertcollins.net-20071022054219-es6z1d4jqvet4rcp
parent: robertc at robertcollins.net-20071022012351-16lm27an2lbzk038
parent: robertc at robertcollins.net-20071022043300-c8sdvyizlgoy3i97
committer: Robert Collins <robertc at robertcollins.net>
branch nick: repository
timestamp: Mon 2007-10-22 15:42:19 +1000
message:
Merge dirstate lookup cache.
modified:
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
------------------------------------------------------------
revno: 2592.1.25.2.7.1.28.1.6.1.3.1.9.2.1.3.74.1.31.3.18.1.9.1.2.1.12.1.8.1.46.1.18.1.1.2.21.2.10.1.1
revision-id:robertc at robertcollins.net-20071022043300-c8sdvyizlgoy3i97
parent: pqm at pqm.ubuntu.com-20071019201226-6z006xotgfe7zmu8
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate.cache
timestamp: Mon 2007-10-22 14:33:00 +1000
message:
Add a cache for dirstate entry lookups.
modified:
bzrlib/dirstate.py dirstate.py-20060728012006-d6mvoihjb3je9peu-1
=== modified file 'bzrlib/dirstate.py'
--- a/bzrlib/dirstate.py 2007-10-10 00:04:46 +0000
+++ b/bzrlib/dirstate.py 2007-10-22 04:33:00 +0000
@@ -345,6 +345,8 @@
self._sha1_file = self._sha1_file_and_mutter
else:
self._sha1_file = osutils.sha_file_by_name
+ self._last_block_index = None
+ self._last_entry_index = None
def __repr__(self):
return "%s(%r)" % \
@@ -1042,6 +1044,12 @@
"""
if key[0:2] == ('', ''):
return 0, True
+ try:
+ if (self._last_block_index is not None and
+ self._dirblocks[self._last_block_index][0] == key[0]):
+ return self._last_block_index, True
+ except IndexError:
+ pass
block_index = bisect_dirblock(self._dirblocks, key[0], 1,
cache=self._split_path_cache)
# _right returns one-past-where-key is so we have to subtract
@@ -1052,6 +1060,7 @@
# simple and correct:
present = (block_index < len(self._dirblocks) and
self._dirblocks[block_index][0] == key[0])
+ self._last_block_index = block_index
return block_index, present
def _find_entry_index(self, key, block):
@@ -1059,9 +1068,24 @@
:return: The entry index, True if the entry for the key is present.
"""
+ len_block = len(block)
+ try:
+ if self._last_entry_index is not None:
+ # mini-bisect here.
+ entry_index = self._last_entry_index + 1
+ # A hit is when the key is after the last slot, and before or
+ # equal to the next slot.
+ if (block[entry_index - 1][0] < key and
+ key <= block[entry_index][0]):
+ self._last_entry_index = entry_index
+ present = block[entry_index][0] == key
+ return entry_index, present
+ except IndexError:
+ pass
entry_index = bisect.bisect_left(block, (key, []))
- present = (entry_index < len(block) and
+ present = (entry_index < len_block and
block[entry_index][0] == key)
+ self._last_entry_index = entry_index
return entry_index, present
@staticmethod
@@ -1353,7 +1377,7 @@
return block_index, 0, False, False
block = self._dirblocks[block_index][1] # access the entries only
entry_index, present = self._find_entry_index(key, block)
- # linear search through present entries at this path to find the one
+ # linear search through entries at this path to find the one
# requested.
while entry_index < len(block) and block[entry_index][0][1] == basename:
if block[entry_index][1][tree_index][0] not in \
@@ -1380,7 +1404,8 @@
"""
self._read_dirblocks_if_needed()
if path_utf8 is not None:
- assert path_utf8.__class__ == str, 'path_utf8 is not a str: %s %s' % (type(path_utf8), path_utf8)
+ assert path_utf8.__class__ == str, ('path_utf8 is not a str: %s %s'
+ % (type(path_utf8), path_utf8))
# path lookups are faster
dirname, basename = osutils.split(path_utf8)
block_index, entry_index, dir_present, file_present = \
More information about the bazaar-commits
mailing list