Rev 4184: Remove the asserts, and change some to AssertionError. in lp:///~jameinel/bzr/lru_cache_linked_lst

John Arbash Meinel john at arbash-meinel.com
Mon Mar 23 02:28:10 GMT 2009


At lp:///~jameinel/bzr/lru_cache_linked_lst

------------------------------------------------------------
revno: 4184
revision-id: john at arbash-meinel.com-20090323022806-snn93cbemn82w1b0
parent: john at arbash-meinel.com-20090322193045-te9xf2ufvsnq09fl
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: lru_cache_linked_lst
timestamp: Sun 2009-03-22 21:28:06 -0500
message:
  Remove the asserts, and change some to AssertionError.
-------------- next part --------------
=== modified file 'bzrlib/lru_cache.py'
--- a/bzrlib/lru_cache.py	2009-03-22 19:30:45 +0000
+++ b/bzrlib/lru_cache.py	2009-03-23 02:28:06 +0000
@@ -89,7 +89,6 @@
             # Nothing to do, this node is already at the head of the queue
             return node.value
         elif node is self._last_recently_used:
-            assert node.prev is not None
             self._last_recently_used = node.prev
         # Remove this node from the old location
         node_prev = node.prev
@@ -109,19 +108,31 @@
         return len(self._cache)
 
     def _walk_lru(self):
-        """Walk the LRU list."""
+        """Walk the LRU list, only meant to be used in tests."""
         node = self._most_recently_used
         if node is not None:
-            assert node.prev is None
+            if node.prev is not None:
+                raise AssertionError('the _most_recently_used entry is not'
+                                     ' supposed to have a previous entry'
+                                     ' %s' % (node,))
         while node is not None:
             if node.next is None:
-                assert node is self._last_recently_used
+                if node is not self._last_recently_used:
+                    raise AssertionError('only the last node should have'
+                                         ' no next value: %s' % (node,))
             else:
-                assert node.next.prev is node
+                if node.next.prev is not node:
+                    raise AssertionError('inconsistency found, node.next.prev'
+                                         ' != node: %s' % (node,))
             if node.prev is None:
-                assert node is self._most_recently_used
+                if node is not self._most_recently_used:
+                    raise AssertionError('only the _most_recently_used should'
+                                         ' not have a previous node: %s'
+                                         % (node,))
             else:
-                assert node.prev.next is node
+                if node.prev.next is not node:
+                    raise AssertionError('inconsistency found, node.prev.next'
+                                         ' != node: %s' % (node,))
             yield node
             node = node.next
 
@@ -196,19 +207,14 @@
         """Record that key was accessed."""
         # Move 'node' to the front of the queue
         if self._most_recently_used is None:
-            assert len(self._cache) == 1
             self._most_recently_used = node
             self._last_recently_used = node
-            assert node.next == None
-            assert node.prev == None
             return
         elif node is self._most_recently_used:
             # Nothing to do, this node is already at the head of the queue
             return
         elif node is self._last_recently_used:
-            assert self._last_recently_used is not None
             self._last_recently_used = node.prev
-            assert self._last_recently_used is not None
         # We've taken care of the tail pointer, remove the node, and insert it
         # at the front
         # REMOVE
@@ -223,23 +229,13 @@
         node.prev = None
 
     def _remove_node(self, node):
-        assert node is not None
         if node is self._last_recently_used:
             self._last_recently_used = node.prev
-        node2 = self._cache.pop(node.key)
-        assert node2 is node
-        del node2
+        self._cache.pop(node.key)
         # If we have removed all entries, remove the head pointer as well
         if self._last_recently_used is None:
-            if len(self._cache) != 0:
-                import pdb; pdb.set_trace()
-            assert len(self._cache) == 0
-            assert self._most_recently_used is node
             self._most_recently_used = None
         node.run_cleanup()
-        # Shouldn't be necessary
-        # node.next = None
-        # node.prev = None
 
     def _remove_lru(self):
         """Remove one entry from the lru, and handle consequences.



More information about the bazaar-commits mailing list