Commit 0ad0819d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

use sort(key=) instead of sort(cmp=) for better performance.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23781 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 16cf48c0
......@@ -137,7 +137,7 @@ class Renderer(Filter):
if self.sort_method is not None:
value_list.sort(self.sort_method)
elif self.sort_id is not None:
value_list.sort(lambda x,y: cmp(x.getProperty(self.sort_id), y.getProperty(self.sort_id)))
value_list.sort(key=lambda x: x.getProperty(self.sort_id))
# If base=1 but base_category is None, it is necessary to guess the base category
# by heuristic.
......
......@@ -968,7 +968,7 @@ class Document(PermanentURLMixIn, XMLObject, UrlMixIn, ConversionCacheMixin, Sna
# Select the first one which is not self and which
# shares the same coordinates
document_list = list(document_list)
document_list.sort(lambda x,y: cmp(x.getId(), y.getId() ))
document_list.sort(key=lambda x: x.getId())
#LOG('[DMS] Existing documents for %s' %self.getSourceReference(), INFO, len(document_list))
for o in document_list:
if o.getRelativeUrl() != self.getRelativeUrl() and\
......
......@@ -228,11 +228,11 @@ class PreferenceTool(BaseTool):
prefs.append(pref)
else :
prefs.append(pref)
prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority()))
prefs.sort(key=lambda x: -x.getPriority())
# add system preferences after user preferences
sys_prefs = [x.getObject() for x in self.searchFolder(portal_type='System Preference', **kw) \
if x.getObject().getProperty('preference_state', 'broken') in ('enabled', 'global')]
sys_prefs.sort(lambda b, a: cmp(a.getPriority(), b.getPriority()))
sys_prefs.sort(key=lambda x: -x.getPriority())
return sys_prefs + prefs
security.declareProtected(Permissions.View, 'getActivePreference')
......
......@@ -639,9 +639,9 @@ class ERP5ShopOrderConduit(ERP5Conduit):
erp5_ship_id_word_list = self.str2id(service_id).split("_")
stor_ship_id_word_list = self.str2id(stor_ship_title).split("_")
erp5_ship_title_word_list = self.str2id(erp5_ship_title).split("_")
erp5_ship_id_word_list.sort(lambda x, y: cmp(str(x), str(y)))
stor_ship_id_word_list.sort(lambda x, y: cmp(str(x), str(y)))
erp5_ship_title_word_list.sort(lambda x, y: cmp(str(x), str(y)))
erp5_ship_id_word_list.sort(key=lambda x: str(x))
stor_ship_id_word_list.sort(key=lambda x: str(x))
erp5_ship_title_word_list.sort(key=lambda x: str(x))
if stor_ship_id_word_list in (erp5_ship_id_word_list, erp5_ship_title_word_list):
shipment_id = service_id
LOG("Service found with method 3 ! >>>>>>>>", 0, repr(shipment_id))
......
......@@ -710,7 +710,7 @@ class ERP5TypeInformationMixIn( FactoryTypeInformation,
def reorderActions(self, REQUEST=None):
"""Reorder actions according to their priorities."""
new_actions = self._cloneActions()
new_actions.sort(lambda x,y: cmp(x.getPriority(), y.getPriority()))
new_actions.sort(key=lambda x: x.getPriority())
self._actions = tuple( new_actions )
if REQUEST is not None:
......
......@@ -551,7 +551,7 @@ class Catalog(Folder,
if value is not None:
property_list.append((property_id, value))
# Sort for easy diff
property_list.sort(lambda x, y: cmp(x[0], y[0]))
property_list.sort(key=lambda x: x[0])
for property in property_list:
property_id = property[0]
value = property[1]
......@@ -576,7 +576,7 @@ class Catalog(Folder,
filter_definition = self.filter_dict[filter_id]
filter_list.append((filter_id, filter_definition))
# Sort for easy diff
filter_list.sort(lambda x, y: cmp(x[0], y[0]))
filter_list.sort(key=lambda x: x[0])
for filter_item in filter_list:
filter_id = filter_item[0]
filter_def = filter_item[1]
......
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