[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py Merged c118895, c118896 from Zope 2.13 branch - these didn't make it into Zope2 trunk which was the base for the spin-off

Hanno Schlichting hannosch at hannosch.eu
Sat Dec 25 14:15:28 EST 2010


Log message for revision 119102:
  Merged c118895, c118896 from Zope 2.13 branch - these didn't make it into Zope2 trunk which was the base for the spin-off
  

Changed:
  U   Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py

-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py	2010-12-25 19:11:52 UTC (rev 119101)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Lazy.py	2010-12-25 19:15:27 UTC (rev 119102)
@@ -145,26 +145,20 @@
     # Don't access data until necessary
 
     def __init__(self, func, seq, length=None):
-        self._seq=seq
-        self._func=func
+        self._seq = seq
+        self._data = {}
+        self._func = func
         if length is not None:
-            self._len=length
+            self._len = length
         else:
             self._len = len(seq)
         self.actual_result_count = self._len
-        self._marker = object()
-        self._data = [self._marker] * self._len
 
-    def __getitem__(self,index):
-        data=self._data
-        try:
-            s=self._seq
-        except AttributeError:
+    def __getitem__(self, index):
+        data = self._data
+        if index in data:
             return data[index]
-
-        value = data[index]
-        if value is self._marker:
-            value = data[index] = self._func(s[index])
+        value = data[index] = self._func(self._seq[index])
         return value
 
 



More information about the checkins mailing list