Rev 4295: When removing a node from an LRUCache, properly remove it from the linked list. in http://bzr.arbash-meinel.com/branches/bzr/jam-integration

John Arbash Meinel john at arbash-meinel.com
Thu Apr 16 03:09:01 BST 2009


At http://bzr.arbash-meinel.com/branches/bzr/jam-integration

------------------------------------------------------------
revno: 4295
revision-id: john at arbash-meinel.com-20090416020821-l02fxbqhx341yo8o
parent: pqm at pqm.ubuntu.com-20090415172601-buxpv8kc1qf9uork
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: jam-integration
timestamp: Wed 2009-04-15 21:08:21 -0500
message:
  When removing a node from an LRUCache, properly remove it from the linked list.
-------------- next part --------------
=== modified file 'bzrlib/lru_cache.py'
--- a/bzrlib/lru_cache.py	2009-03-30 11:49:32 +0000
+++ b/bzrlib/lru_cache.py	2009-04-16 02:08:21 +0000
@@ -235,6 +235,14 @@
         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 = node.prev
+        # And remove this node's pointers
+        node.prev = 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-16 02:08:21 +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