[Checkins] SVN: zc.sourcefactory/trunk/ - fixed another scalability
bug caused by missing __nonzero__
Benji York
benji at zope.com
Wed Apr 9 11:23:12 EDT 2008
Log message for revision 85190:
- fixed another scalability bug caused by missing __nonzero__
- updating CHANGES.txt with previous release info
Changed:
U zc.sourcefactory/trunk/CHANGES.txt
U zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.py
U zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.txt
-=-
Modified: zc.sourcefactory/trunk/CHANGES.txt
===================================================================
--- zc.sourcefactory/trunk/CHANGES.txt 2008-04-09 15:15:12 UTC (rev 85189)
+++ zc.sourcefactory/trunk/CHANGES.txt 2008-04-09 15:23:12 UTC (rev 85190)
@@ -2,22 +2,37 @@
Changes
=======
-After 0.2.1
-===========
+0.3.2 (2008-04-09)
+==================
+
+ - Fixed scalability bug caused by missing __nonzero__ on ValueMappingSource
+
+
+0.3.1 (2008-02-12)
+==================
+
+ - Fixed scalability bug caused by missing __nonzero__ on BasicSourceFactory
+
+
+0.3.0 (??????????)
+==================
+
- Added class-level defaults for attributes that are declared in the
interfaces to not have the Zope 2 security machinery complain about
them.
+
0.2.1 - 2007-07-10
==================
- Fixed a bug in the contextual token policy that was handling the
resolution of values for a given token incorrectly.
-0.2 - 2007-07-10
-================
+0.2.0 - 2007-07-10
+==================
+
- Added a contextual token policy interface that allows getToken and
getValue to access the cotext for contextual sources.
Modified: zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.py
===================================================================
--- zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.py 2008-04-09 15:15:12 UTC (rev 85189)
+++ zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.py 2008-04-09 15:23:12 UTC (rev 85190)
@@ -71,3 +71,8 @@
def __len__(self):
return len(self.base)
+
+ def __nonzero__(self):
+ for dummy in self.base:
+ return True
+ return False
Modified: zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.txt
===================================================================
--- zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.txt 2008-04-09 15:15:12 UTC (rev 85189)
+++ zc.sourcefactory/trunk/src/zc/sourcefactory/mapping.txt 2008-04-09 15:23:12 UTC (rev 85190)
@@ -43,3 +43,26 @@
True
>>> 1 in bound_source
False
+
+
+Scaling
+-------
+
+Sometimes the number of items available through a source is very large. So
+large that you only want to access them if absolutely neccesary. One such
+occasion is with truth-testing a source. By default Python will call
+__nonzero__ to get the boolean value of an object, but if that isn't available
+__len__ is called to see what it returns. That might be very expensive, so we
+want to make sure it isn't called.
+
+ >>> class ExpensiveSource(object):
+ ... def __len__(self):
+ ... raise RuntimeError("oops, don't want to call __len__")
+ ...
+ ... def __iter__(self):
+ ... return iter(xrange(999999))
+
+ >>> expensive_source = ExpensiveSource()
+ >>> mapped_source = ValueMappingSource(expensive_source, map)
+ >>> bool(mapped_source)
+ True
More information about the Checkins
mailing list