[Zodb-checkins] SVN: ZODB/trunk/src/ZODB/MappingStorage.py Merge rev 28208 from ZODB 3.3 branch.

Dmitry Vasiliev dima at hlabs.spb.ru
Mon Oct 18 06:01:20 EDT 2004


Log message for revision 28209:
  Merge rev 28208 from ZODB 3.3 branch.
  
  Code cleanups.
  

Changed:
  U   ZODB/trunk/src/ZODB/MappingStorage.py

-=-
Modified: ZODB/trunk/src/ZODB/MappingStorage.py
===================================================================
--- ZODB/trunk/src/ZODB/MappingStorage.py	2004-10-18 09:43:30 UTC (rev 28208)
+++ ZODB/trunk/src/ZODB/MappingStorage.py	2004-10-18 10:01:20 UTC (rev 28209)
@@ -22,15 +22,17 @@
 """
 
 from ZODB.utils import u64, z64
-from ZODB import BaseStorage
+from ZODB.BaseStorage import BaseStorage
 from ZODB import POSException
 from persistent.TimeStamp import TimeStamp
 
 
-class MappingStorage(BaseStorage.BaseStorage):
+class MappingStorage(BaseStorage):
+
     def __init__(self, name='Mapping Storage'):
-        BaseStorage.BaseStorage.__init__(self, name)
+        BaseStorage.__init__(self, name)
         self._index = {}
+        # FIXME: Why we don't use dict for _tindex?
         self._tindex = []
         self._ltid = None
         # Note: If you subclass this and use a persistent mapping facility
@@ -41,12 +43,15 @@
         return len(self._index)
 
     def getSize(self):
-        # These constants are for Python object memory overheads
-        s = 32
-        for oid in self._index.keys():
-            p = self._index[oid]
-            s += 56 + len(p)
-        return s
+        self._lock_acquire()
+        try:
+            # These constants are for Python object memory overheads
+            s = 32
+            for p in self._index.itervalues():
+                s += 56 + len(p)
+            return s
+        finally:
+            self._lock_release()
 
     def load(self, oid, version):
         self._lock_acquire()
@@ -70,8 +75,7 @@
         self._lock_acquire()
         try:
             # The tid is the first 8 bytes of the buffer.
-            s = self._index[oid]
-            return s[:8]
+            return self._index[oid][:8]
         finally:
             self._lock_release()
 
@@ -81,13 +85,12 @@
             raise POSException.StorageTransactionError(self, transaction)
 
         if version:
-            raise POSException.Unsupported, "Versions aren't supported"
+            raise POSException.Unsupported("Versions aren't supported")
 
         self._lock_acquire()
         try:
-            if self._index.has_key(oid):
-                old = self._index[oid]
-                oserial = old[:8]
+            if oid in self._index:
+                oserial = self._index[oid][:8]
                 if serial != oserial:
                     raise POSException.ConflictError(oid=oid,
                                                      serials=(oserial, serial),
@@ -102,8 +105,7 @@
         self._tindex = []
 
     def _finish(self, tid, user, desc, ext):
-        for oid, p in self._tindex:
-            self._index[oid] = p
+        self._index.update(dict(self._tindex))
         self._ltid = self._tid
 
     def lastTransaction(self):
@@ -119,17 +121,16 @@
             pindex = {}
             while rootl:
                 oid = rootl.pop()
-                if pindex.has_key(oid):
+                if oid in pindex:
                     continue
                 # Scan non-version pickle for references
                 r = self._index[oid]
                 pindex[oid] = r
-                p = r[8:]
-                referencesf(p, rootl)
+                referencesf(r[8:], rootl)
 
             # Now delete any unreferenced entries:
             for oid in self._index.keys():
-                if not pindex.has_key(oid):
+                if oid not in pindex:
                     del self._index[oid]
 
         finally:
@@ -137,13 +138,12 @@
 
     def _splat(self):
         """Spit out a string showing state."""
-        o = []
-        o.append('Index:')
+        o = ['Index:']
         keys = self._index.keys()
         keys.sort()
         for oid in keys:
             r = self._index[oid]
             o.append('  %s: %s, %s' %
-                     (u64(oid),TimeStamp(r[:8]),`r[8:]`))
+                     (u64(oid), TimeStamp(r[:8]), repr(r[8:])))
 
         return '\n'.join(o)



More information about the Zodb-checkins mailing list