[Checkins] SVN: zc.dict/trunk/src/zc/dict/dict. Unroll update so that the length does not need to be recalculated.

Albertas Agejevas alga at pov.lt
Wed Jul 4 10:56:34 EDT 2007


Log message for revision 77395:
  Unroll update so that the length does not need to be recalculated.
  

Changed:
  U   zc.dict/trunk/src/zc/dict/dict.py
  U   zc.dict/trunk/src/zc/dict/dict.txt

-=-
Modified: zc.dict/trunk/src/zc/dict/dict.py
===================================================================
--- zc.dict/trunk/src/zc/dict/dict.py	2007-07-04 14:47:28 UTC (rev 77394)
+++ zc.dict/trunk/src/zc/dict/dict.py	2007-07-04 14:56:33 UTC (rev 77395)
@@ -46,8 +46,8 @@
         self._len.change(-1)
 
     def update(self, other):
-        self._data.update(other)
-        self._len.set(len(self._data))
+        for k, v in other.iteritems():
+            self[k] = v
 
     def clear(self):
         self._data.clear()

Modified: zc.dict/trunk/src/zc/dict/dict.txt
===================================================================
--- zc.dict/trunk/src/zc/dict/dict.txt	2007-07-04 14:47:28 UTC (rev 77394)
+++ zc.dict/trunk/src/zc/dict/dict.txt	2007-07-04 14:56:33 UTC (rev 77395)
@@ -29,8 +29,8 @@
    >>> d._len()
    2
 
-As after an update operation we cannot easily adjust the length, it is
-recalculated:
+In order to keep updates efficient for small changes, we unroll them
+as a series of setitems.
 
    >>> d.update({'bar': 'moo', 'ding': 'dong', 'beep': 'beep'})
    >>> len(d)



More information about the Checkins mailing list