[Checkins] SVN: Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py Bring back multi-key sorting to mormal speed, if all keys should be sorted in the same direction. The cmp() approach is about 10x slower

Hano Schlichting cvs-admin at zope.org
Sat Apr 7 20:14:00 UTC 2012


Log message for revision 125090:
  Bring back multi-key sorting to mormal speed, if all keys should be sorted in the same direction. The cmp() approach is about 10x slower
  

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 19:55:52 UTC (rev 125089)
+++ Products.ZCatalog/trunk/src/Products/ZCatalog/Catalog.py	2012-04-07 20:13:56 UTC (rev 125090)
@@ -1095,6 +1095,14 @@
     The length of sort_spec must match the length of the first value in each
     list entry given via `items`.
     """
+    first = sort_spec[0]
+    different = any([True for s in sort_spec if s != first])
+    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))
+        return items
+
     comparers = []
     for i, v in enumerate(sort_spec):
         comparers.append((itemgetter(i), v))



More information about the checkins mailing list