Rev 3911: type(node) is InternalNode is supposedly better than isinstance(node, InternalNode) in http://bazaar.launchpad.net/%7Ebzr/bzr/brisbane-core

John Arbash Meinel john at arbash-meinel.com
Thu Mar 26 18:04:09 GMT 2009


At http://bazaar.launchpad.net/%7Ebzr/bzr/brisbane-core

------------------------------------------------------------
revno: 3911
revision-id: john at arbash-meinel.com-20090326180307-yktd7ny3mees1v6t
parent: john at arbash-meinel.com-20090326175542-qmb46mw1d8zt5k1l
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: brisbane-core
timestamp: Thu 2009-03-26 13:03:07 -0500
message:
  type(node) is InternalNode is supposedly better than isinstance(node, InternalNode)
-------------- next part --------------
=== modified file 'bzrlib/chk_map.py'
--- a/bzrlib/chk_map.py	2009-03-26 17:55:42 +0000
+++ b/bzrlib/chk_map.py	2009-03-26 18:03:07 +0000
@@ -172,7 +172,7 @@
                 key_str = ' None'
         result.append('%s%r %s%s' % (indent, prefix, node.__class__.__name__,
                                      key_str))
-        if isinstance(node, InternalNode):
+        if type(node) is InternalNode:
             # Trigger all child nodes to get loaded
             list(node._iter_nodes(self._store))
             for prefix, sub in sorted(node._items.iteritems()):
@@ -437,7 +437,7 @@
 
     def key(self):
         """Return the key for this map."""
-        if isinstance(self._root_node, tuple):
+        if type(self._root_node) is tuple:
             return self._root_node
         else:
             return self._root_node._key
@@ -471,7 +471,7 @@
     def unmap(self, key, check_remap=True):
         """remove key from the map."""
         self._ensure_root()
-        if isinstance(self._root_node, InternalNode):
+        if type(self._root_node) is InternalNode:
             unmapped = self._root_node.unmap(self._store, key,
                 check_remap=check_remap)
         else:
@@ -481,7 +481,7 @@
     def _check_remap(self):
         """Check if nodes can be collapsed."""
         self._ensure_root()
-        if isinstance(self._root_node, InternalNode):
+        if type(self._root_node) is InternalNode:
             self._root_node._check_remap(self._store)
 
     def _save(self):
@@ -1047,7 +1047,7 @@
             # new child needed:
             child = self._new_child(search_key, LeafNode)
         old_len = len(child)
-        if isinstance(child, LeafNode):
+        if type(child) is LeafNode:
             old_size = child._current_size()
         else:
             old_size = None
@@ -1059,7 +1059,7 @@
             self._items[search_key] = child
             self._key = None
             new_node = self
-            if isinstance(child, LeafNode):
+            if type(child) is LeafNode:
                 if old_size is None:
                     # The old node was an InternalNode which means it has now
                     # collapsed, so we need to check if it will chain to a
@@ -1213,7 +1213,7 @@
         if len(self._items) == 1:
             # this node is no longer needed:
             return self._items.values()[0]
-        if isinstance(unmapped, InternalNode):
+        if type(unmapped) is InternalNode:
             return self
         if check_remap:
             return self._check_remap(store)
@@ -1259,7 +1259,7 @@
         #   c) With 255-way fan out, we don't want to read all 255 and destroy
         #      the page cache, just to determine that we really don't need it.
         for node, _ in self._iter_nodes(store, batch_size=16):
-            if isinstance(node, InternalNode):
+            if type(node) is InternalNode:
                 # Without looking at any leaf nodes, we are sure
                 return self
             for key, value in node._items.iteritems():
@@ -1300,7 +1300,7 @@
         # care about external references.
         node = _deserialise(bytes, record.key, search_key_func=None)
         if record.key in uninteresting_keys:
-            if isinstance(node, InternalNode):
+            if type(node) is InternalNode:
                 next_uninteresting.update(node.refs())
             else:
                 # We know we are at a LeafNode, so we can pass None for the
@@ -1308,7 +1308,7 @@
                 uninteresting_items.update(node.iteritems(None))
         else:
             interesting_records.append(record)
-            if isinstance(node, InternalNode):
+            if type(node) is InternalNode:
                 next_interesting.update(node.refs())
             else:
                 interesting_items.update(node.iteritems(None))
@@ -1364,7 +1364,7 @@
             # We don't care about search_key_func for this code, because we
             # only care about external references.
             node = _deserialise(bytes, record.key, search_key_func=None)
-            if isinstance(node, InternalNode):
+            if type(node) is InternalNode:
                 # uninteresting_prefix_chks.update(node._items.iteritems())
                 chks = node._items.values()
                 # TODO: We remove the entries that are already in
@@ -1435,7 +1435,7 @@
             # We don't care about search_key_func for this code, because we
             # only care about external references.
             node = _deserialise(bytes, record.key, search_key_func=None)
-            if isinstance(node, InternalNode):
+            if type(node) is InternalNode:
                 # all_uninteresting_chks grows large, as it lists all nodes we
                 # don't want to process (including already seen interesting
                 # nodes).



More information about the bazaar-commits mailing list