Commit 7eedfdbc authored by Hanno Schlichting's avatar Hanno Schlichting

Combine reverse and sort into one where possible

parent d8557642
......@@ -655,9 +655,10 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
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 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# 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)
......
......@@ -46,9 +46,12 @@ def createDatabase():
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 @@ class TestMerge(CatalogBase, unittest.TestCase):
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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment