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