Rev 3893: comment update in http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

John Arbash Meinel john at arbash-meinel.com
Wed Dec 10 22:27:27 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

------------------------------------------------------------
revno: 3893
revision-id: john at arbash-meinel.com-20081210222704-465gxu7k0wehug6o
parent: john at arbash-meinel.com-20081210222654-7sem2ud7397cd8vg
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Wed 2008-12-10 16:27:04 -0600
message:
  comment update
-------------- next part --------------
=== modified file 'bzrlib/tests/test_fifo_cache.py'
--- a/bzrlib/tests/test_fifo_cache.py	2008-12-09 22:26:40 +0000
+++ b/bzrlib/tests/test_fifo_cache.py	2008-12-10 22:27:04 +0000
@@ -41,6 +41,12 @@
         self.assertEqual([2], list(c.itervalues()))
         self.assertEqual({1: 2}, c)
 
+    def test_cache_size(self):
+        c = fifo_cache.FIFOCache()
+        self.assertEqual(100, c.cache_size())
+        c.resize(20, 5)
+        self.assertEqual(20, c.cache_size())
+
     def test_missing(self):
         c = fifo_cache.FIFOCache()
         self.assertRaises(KeyError, c.__getitem__, 1)
@@ -114,6 +120,45 @@
         c = fifo_cache.FIFOCache()
         self.assertRaises(NotImplementedError, c.popitem)
 
+    def test_resize_smaller(self):
+        c = fifo_cache.FIFOCache()
+        c[1] = 2
+        c[2] = 3
+        c[3] = 4
+        c[4] = 5
+        c[5] = 6
+        # No cleanup, because it is the exact size
+        c.resize(5)
+        self.assertEqual({1: 2, 2: 3, 3: 4, 4: 5, 5: 6}, c)
+        self.assertEqual(5, c.cache_size())
+        # Adding one more will trigger a cleanup, though
+        c[6] = 7
+        self.assertEqual({3: 4, 4: 5, 5: 6, 6: 7}, c)
+        c.resize(3, 2)
+        self.assertEqual({5: 6, 6: 7}, c)
+
+    def test_resize_larger(self):
+        c = fifo_cache.FIFOCache(5, 4)
+        c[1] = 2
+        c[2] = 3
+        c[3] = 4
+        c[4] = 5
+        c[5] = 6
+        # No cleanup, because it is the exact size
+        c.resize(10)
+        self.assertEqual({1: 2, 2: 3, 3: 4, 4: 5, 5: 6}, c)
+        self.assertEqual(10, c.cache_size())
+        c[6] = 7
+        c[7] = 8
+        c[8] = 9
+        c[9] = 10
+        c[10] = 11
+        self.assertEqual({1: 2, 2: 3, 3: 4, 4: 5, 5: 6, 6: 7, 7: 8, 8: 9,
+                          9: 10, 10: 11}, c)
+        c[11] = 12
+        self.assertEqual({4: 5, 5: 6, 6: 7, 7: 8, 8: 9, 9: 10, 10: 11,
+                          11: 12}, c)
+
     def test_setdefault(self):
         c = fifo_cache.FIFOCache(5, 4)
         c['one'] = 1
@@ -208,6 +253,7 @@
         self.assertEqual(['2'], c.values())
         self.assertEqual(['2'], list(c.itervalues()))
         self.assertEqual({1: '2'}, c)
+        self.assertEqual(1024*1024, c.cache_size())
 
     def test_missing(self):
         c = fifo_cache.FIFOSizeCache()
@@ -248,3 +294,32 @@
         c[1] = 'abcdefgh'
         self.assertEqual({}, c)
         self.assertEqual(0, c._value_size)
+
+    def test_resize_smaller(self):
+        c = fifo_cache.FIFOSizeCache(20, 16)
+        c[1] = 'a'
+        c[2] = 'bc'
+        c[3] = 'def'
+        c[4] = 'ghij'
+        # No cleanup, because it is the exact size
+        c.resize(10, 8)
+        self.assertEqual({1: 'a', 2: 'bc', 3: 'def', 4: 'ghij'}, c)
+        self.assertEqual(10, c.cache_size())
+        # Adding one more will trigger a cleanup, though
+        c[5] = 'k'
+        self.assertEqual({3: 'def', 4: 'ghij', 5: 'k'}, c)
+        c.resize(5, 4)
+        self.assertEqual({5: 'k'}, c)
+
+    def test_resize_larger(self):
+        c = fifo_cache.FIFOSizeCache(10, 8)
+        c[1] = 'a'
+        c[2] = 'bc'
+        c[3] = 'def'
+        c[4] = 'ghij'
+        c.resize(12, 10)
+        self.assertEqual({1: 'a', 2: 'bc', 3: 'def', 4: 'ghij'}, c)
+        c[5] = 'kl'
+        self.assertEqual({1: 'a', 2: 'bc', 3: 'def', 4: 'ghij', 5: 'kl'}, c)
+        c[6] = 'mn'
+        self.assertEqual({4: 'ghij', 5: 'kl', 6: 'mn'}, c)

=== modified file 'bzrlib/xml8.py'
--- a/bzrlib/xml8.py	2008-12-10 21:37:12 +0000
+++ b/bzrlib/xml8.py	2008-12-10 22:27:04 +0000
@@ -385,7 +385,7 @@
         #   7.1s    InventoryFile.copy()
         #   2.4s    InventoryDirectory.copy()
         #   0.4s    decoding unique entries
-        #   1.6s    decoding entries
+        #   1.6s    decoding entries after FIFO fills up
         #   0.8s    Adding nodes to FIFO (including flushes)
         #   0.1s    cache miss lookups
         # Using an LRU cache



More information about the bazaar-commits mailing list