[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py Tweak multi-sort some more. Sorting via key is so much faster, it still offsets the wrong sorting on secondary indexes
Hano Schlichting
cvs-admin at zope.org
Sat Apr 7 20:55:31 UTC 2012
Log message for revision 125092:
Tweak multi-sort some more. Sorting via key is so much faster, it still offsets the wrong sorting on secondary indexes
Changed:
U Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
-=-
Modified: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py
===================================================================
--- Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-04-07 20:32:56 UTC (rev 125091)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py 2012-04-07 20:55:27 UTC (rev 125092)
@@ -1100,10 +1100,13 @@
"""
first = sort_spec[0]
different = any([True for s in sort_spec if s != first])
+ first_reverse = first != 1 and True or False
+
+ # always do an in-place sort. The default sort via key is really fast and
+ # the later cmp approach is efficient when getting mostly sorted data.
+ items.sort(reverse=first_reverse, key=itemgetter(0))
if not different:
- # if we can, we do an in-place sort
- reverse = first != 1 and True or False
- items.sort(reverse=reverse, key=itemgetter(0))
+ # if all keys are sorted in the same direction, we are done
return items
comparers = []
@@ -1116,4 +1119,5 @@
if result:
return order * result
return 0
- return sorted(items, cmp=comparer)
+ items.sort(cmp=comparer)
+ return items
More information about the checkins
mailing list