Rev 4289: Properly remove the nodes from the internal linked list in _remove_node. in lp:///~jameinel/bzr/1.15-lru-gc

John Arbash Meinel john at arbash-meinel.com
Wed Apr 15 19:08:45 BST 2009


At lp:///~jameinel/bzr/1.15-lru-gc

------------------------------------------------------------
revno: 4289
revision-id: john at arbash-meinel.com-20090415180816-gt70a2f8zdy9zkn9
parent: john at arbash-meinel.com-20090414194349-0drrvwi7n9ju3e51
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: 1.15-lru-gc
timestamp: Wed 2009-04-15 13:08:16 -0500
message:
  Properly remove the nodes from the internal linked list in _remove_node.
-------------- next part --------------
=== modified file 'bzrlib/lru_cache.py'
--- a/bzrlib/lru_cache.py	2009-04-14 19:43:49 +0000
+++ b/bzrlib/lru_cache.py	2009-04-15 18:08:16 +0000
@@ -233,19 +233,25 @@
         node.prev_key = None
 
     def _remove_node(self, node):
-        if node is None:
-            import pdb; pdb.set_trace()
+        if node.prev_key is None:
+            node_prev = None
+        else:
+            node_prev = self._cache[node.prev_key]
         if node is self._last_recently_used:
-            if node.prev_key is None:
-                node_prev = None
-            else:
-                node_prev = self._cache[node.prev_key]
             self._last_recently_used = node_prev
         self._cache.pop(node.key)
         # If we have removed all entries, remove the head pointer as well
         if self._last_recently_used is None:
             self._most_recently_used = None
         node.run_cleanup()
+        # Now remove this node from the linked list
+        if node_prev is not None:
+            node_prev.next = node.next
+        if node.next is not None:
+            node.next.prev_key = node.prev_key
+        # And remove this node's pointers
+        node.prev_key = None
+        node.next = None
 
     def _remove_lru(self):
         """Remove one entry from the lru, and handle consequences.

=== modified file 'bzrlib/tests/test_lru_cache.py'
--- a/bzrlib/tests/test_lru_cache.py	2009-03-24 17:01:50 +0000
+++ b/bzrlib/tests/test_lru_cache.py	2009-04-15 18:08:16 +0000
@@ -138,6 +138,8 @@
 
         # We hit the max
         self.assertEqual(10, len(cache))
+        self.assertEqual([11, 10, 9, 1, 8, 7, 6, 5, 4, 3],
+                         [n.key for n in cache._walk_lru()])
 
     def test_cleanup_shrinks_to_after_clean_count(self):
         cache = lru_cache.LRUCache(max_cache=5, after_cleanup_count=3)



More information about the bazaar-commits mailing list