Skip to content

Commit

Permalink
Speed up column sorting (helps a lot when 10k of items are involved,
Browse files Browse the repository at this point in the history
especially when you have a moderately expensive getSortKey function)
  • Loading branch information
Ignas committed Oct 20, 2008
1 parent 62c9b6f commit 3960f83
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/zc/table/column.py
Expand Up @@ -59,10 +59,12 @@ def _sort(self, items, formatter, start, stop, sorters, multiplier):
else:
items = list(items) # don't mutate original
getSortKey = self.getSortKey
items.sort(
lambda a, b: multiplier*cmp(getSortKey(a, formatter),
getSortKey(b, formatter)))
return items

# let's do decorate, sort, undecorate trick here to conserve time
tmp_items = [(getSortKey(item, formatter), item) for item in items]
tmp_items.sort(lambda a, b: multiplier*cmp(a[0], b[0]))

return [item for key, item in tmp_items]

def sort(self, items, formatter, start, stop, sorters):
return self._sort(items, formatter, start, stop, sorters, 1)
Expand Down

0 comments on commit 3960f83

Please sign in to comment.