Rev 3897: Change the _entry_cache into class specific. in http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

John Arbash Meinel john at arbash-meinel.com
Thu Dec 11 20:09:27 GMT 2008


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

------------------------------------------------------------
revno: 3897
revision-id: john at arbash-meinel.com-20081211200919-0cymakwpvgc5xjtn
parent: john at arbash-meinel.com-20081210230600-d84wjysaeu1caoea
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Thu 2008-12-11 14:09:19 -0600
message:
  Change the _entry_cache into class specific.
  
  This means that each Serializer will have its own entry_cache.
  But that will ensure any differences in results from different
  serializers will not be propagated. And it doesn't matter for
  most use cases, as we are really only dealing with one serializer
  at a time.
-------------- next part --------------
=== modified file 'bzrlib/xml8.py'
--- a/bzrlib/xml8.py	2008-12-10 23:05:21 +0000
+++ b/bzrlib/xml8.py	2008-12-11 20:09:19 +0000
@@ -40,8 +40,6 @@
     "<":"&lt;",
     ">":"&gt;",
     }
-# A cache of InventoryEntry objects
-_entry_cache = fifo_cache.FIFOCache(10*1000)
 
 
 def _ensure_utf8_re():
@@ -148,7 +146,7 @@
     Its revision format number matches its inventory number.
     """
 
-    __slots__ = []
+    __slots__ = ['_entry_cache']
 
     root_id = None
     support_altered_by_hack = True
@@ -159,6 +157,9 @@
     format_num = '8'
     revision_format_num = None
 
+    def __init__(self):
+        self._entry_cache = fifo_cache.FIFOCache(10*1024)
+
     def _check_revisions(self, inv):
         """Extension point for subclasses to check during serialisation.
 
@@ -190,10 +191,10 @@
         """
         # 1.5 times might also be reasonable.
         recommended_cache_size = inv_size * 2
-        if _entry_cache.cache_size() < recommended_cache_size:
+        if self._entry_cache.cache_size() < recommended_cache_size:
             trace.mutter('Resizing the inventory entry cache to %d',
                          recommended_cache_size)
-            _entry_cache.resize(recommended_cache_size)
+            self._entry_cache.resize(recommended_cache_size)
 
     def write_inventory_to_lines(self, inv):
         """Return a list of lines with the encoded inventory."""
@@ -422,7 +423,7 @@
         key = (file_id, revision)
         try:
             # We copy it, because some operatations may mutate it
-            cached_ie = _entry_cache[key]
+            cached_ie = self._entry_cache[key]
         except KeyError:
             pass
         else:
@@ -467,7 +468,7 @@
             raise errors.UnsupportedInventoryKind(kind)
         ie.revision = revision
         if revision is not None:
-            _entry_cache[key] = ie
+            self._entry_cache[key] = ie
 
         return ie
 



More information about the bazaar-commits mailing list