Rev 3900: Bring in optimizations to Inventory._make_delta. in http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache
John Arbash Meinel
john at arbash-meinel.com
Thu Dec 11 20:59:37 GMT 2008
At http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache
------------------------------------------------------------
revno: 3900
revision-id: john at arbash-meinel.com-20081211205928-rmjy6scj28u7l8l3
parent: john at arbash-meinel.com-20081211203350-iur6tsuvq9gtswe9
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Thu 2008-12-11 14:59:28 -0600
message:
Bring in optimizations to Inventory._make_delta.
-------------- next part --------------
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2008-12-11 20:22:14 +0000
+++ b/bzrlib/inventory.py 2008-12-11 20:59:28 +0000
@@ -1238,20 +1238,33 @@
def _make_delta(self, old):
"""Make an inventory delta from two inventories."""
- old_ids = set(old)
- new_ids = set(self)
+ old_getter = getattr(old, '_byid', old)
+ new_getter = self._byid
+ old_ids = set(old_getter)
+ new_ids = set(new_getter)
adds = new_ids - old_ids
deletes = old_ids - new_ids
- common = old_ids.intersection(new_ids)
+ if not adds and not deletes:
+ common = new_ids
+ else:
+ common = old_ids.intersection(new_ids)
delta = []
for file_id in deletes:
delta.append((old.id2path(file_id), None, file_id, None))
for file_id in adds:
delta.append((None, self.id2path(file_id), file_id, self[file_id]))
for file_id in common:
- if old[file_id] != self[file_id]:
+ new_ie = new_getter[file_id]
+ old_ie = old_getter[file_id]
+ # If xml_serializer returns the cached InventoryEntries (rather
+ # than always doing .copy()), inlining the 'is' check saves 2.7M
+ # calls to __eq__. Under lsprof this saves 20s => 6s.
+ # It is a minor improvement without lsprof.
+ if old_ie is new_ie or old_ie == new_ie:
+ continue
+ else:
delta.append((old.id2path(file_id), self.id2path(file_id),
- file_id, self[file_id]))
+ file_id, new_ie))
return delta
def remove_recursive_id(self, file_id):
More information about the bazaar-commits
mailing list