Rev 2329: Minor performance optimisation in _generate_inventory by avoiding normalisation checks and just using a factory to create the inventory entries. in sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/
Robert Collins
robertc at robertcollins.net
Fri Feb 16 02:40:58 GMT 2007
At sftp://bazaar.launchpad.net/%7Ebzr/bzr/dirstate/
------------------------------------------------------------
revno: 2329
revision-id: robertc at robertcollins.net-20070216023942-8oxrm3qtriwc54w0
parent: robertc at robertcollins.net-20070216022139-bia82eszdktack3k
committer: Robert Collins <robertc at robertcollins.net>
branch nick: dirstate
timestamp: Fri 2007-02-16 13:39:42 +1100
message:
Minor performance optimisation in _generate_inventory by avoiding normalisation checks and just using a factory to create the inventory entries.
modified:
bzrlib/inventory.py inventory.py-20050309040759-6648b84ca2005b37
bzrlib/workingtree_4.py workingtree_4.py-20070208044105-5fgpc5j3ljlh5q6c-1
=== modified file 'bzrlib/inventory.py'
--- a/bzrlib/inventory.py 2007-02-14 22:25:04 +0000
+++ b/bzrlib/inventory.py 2007-02-16 02:39:42 +0000
@@ -1301,6 +1301,12 @@
return self.root is not None and file_id == self.root.file_id
+entry_factory = {
+ 'directory':InventoryDirectory,
+ 'file':InventoryFile,
+ 'symlink':InventoryLink,
+}
+
def make_entry(kind, name, parent_id, file_id=None):
"""Create an inventory entry.
@@ -1325,14 +1331,11 @@
# if the error was raised with the full path
raise errors.InvalidNormalization(name)
- if kind == 'directory':
- return InventoryDirectory(file_id, name, parent_id)
- elif kind == 'file':
- return InventoryFile(file_id, name, parent_id)
- elif kind == 'symlink':
- return InventoryLink(file_id, name, parent_id)
- else:
+ try:
+ factory = entry_factory[kind]
+ except KeyError:
raise BzrError("unknown kind %r" % kind)
+ return factory(file_id, name, parent_id)
_NAME_RE = None
=== modified file 'bzrlib/workingtree_4.py'
--- a/bzrlib/workingtree_4.py 2007-02-16 02:21:39 +0000
+++ b/bzrlib/workingtree_4.py 2007-02-16 02:39:42 +0000
@@ -62,7 +62,7 @@
from bzrlib import symbol_versioning
from bzrlib.decorators import needs_read_lock, needs_write_lock
-from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, make_entry
+from bzrlib.inventory import InventoryEntry, Inventory, ROOT_ID, entry_factory
from bzrlib.lockable_files import LockableFiles, TransportLock
from bzrlib.lockdir import LockDir
import bzrlib.mutabletree
@@ -221,7 +221,7 @@
continue
parent_id = parent_ids[dirname]
file_id = fileid_utf8.decode('utf8')
- entry = make_entry(kind, name.decode('utf8'), parent_id, file_id)
+ entry = entry_factory[kind](file_id, name.decode('utf8'), parent_id)
if kind == 'file':
#entry.executable = executable
#entry.text_size = size
@@ -824,7 +824,7 @@
continue
parent_id = parent_ids[dirname]
file_id = line[0][3].decode('utf8')
- entry = make_entry(kind, name.decode('utf8'), parent_id, file_id)
+ entry = entry_factory[kind](file_id, name.decode('utf8'), parent_id)
entry.revision = revid.decode('utf8')
if kind == 'file':
entry.executable = executable
More information about the bazaar-commits
mailing list