[Zope-Checkins] SVN: Zope/trunk/src/Products/ZCatalog/ Combine reverse and sort into one where possible
Hanno Schlichting
hannosch at hannosch.eu
Sun Aug 1 10:46:11 EDT 2010
Log message for revision 115334:
Combine reverse and sort into one where possible
Changed:
U Zope/trunk/src/Products/ZCatalog/Catalog.py
U Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py
-=-
Modified: Zope/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-08-01 14:42:33 UTC (rev 115333)
+++ Zope/trunk/src/Products/ZCatalog/Catalog.py 2010-08-01 14:46:10 UTC (rev 115334)
@@ -655,9 +655,10 @@
append((k, intset, _self__getitem__))
# Note that sort keys are unique.
- result.sort()
if reverse:
- result.reverse()
+ result.sort(reverse=True)
+ else:
+ result.sort()
result = LazyCat(LazyValues(result), length)
elif limit is None or (limit * 4 > rlen):
# Iterate over the result set getting sort keys from the index
@@ -674,9 +675,10 @@
# results with those of other catalogs while avoiding
# the cost of instantiating a LazyMap per result
if merge:
- result.sort()
if reverse:
- result.reverse()
+ result.sort(reverse=True)
+ else:
+ result.sort()
if limit is not None:
result = result[:limit]
result = LazyValues(result)
Modified: Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py
===================================================================
--- Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py 2010-08-01 14:42:33 UTC (rev 115333)
+++ Zope/trunk/src/Products/ZCatalog/tests/test_catalog.py 2010-08-01 14:46:10 UTC (rev 115334)
@@ -46,9 +46,12 @@
app = createDatabase()
-def sort(iterable):
+def sort(iterable, reverse=False):
L = list(iterable)
- L.sort()
+ if reverse:
+ L.sort(reverse=True)
+ else:
+ L.sort()
return L
@@ -532,8 +535,7 @@
for cat in self.catalogs]
merged_rids = [r.getRID() for r in mergeResults(
results, has_sort_keys=True, reverse=True)]
- expected = sort(chain(*results))
- expected.reverse()
+ expected = sort(chain(*results), reverse=True)
expected = [rid for sortkey, rid, getitem in expected]
self.assertEqual(merged_rids, expected)
More information about the Zope-Checkins
mailing list