Commit a8111bc5 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@23772 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 5049f5ce
...@@ -677,7 +677,7 @@ class AmortisationRule(Rule): ...@@ -677,7 +677,7 @@ class AmortisationRule(Rule):
# We have each matching ratio. Now we need to match each amortisation period # We have each matching ratio. Now we need to match each amortisation period
# according to these ratio : the highest ratio gets the priority, then the next # according to these ratio : the highest ratio gets the priority, then the next
# highest is taken into account if corresponding resources are free, and so on # highest is taken into account if corresponding resources are free, and so on
matching_ratio_list.sort(lambda a, b: - cmp(a['ratio'], b['ratio'])) matching_ratio_list.sort(key=lambda x: -x['ratio'])
calculated_to_match = calculated_period_dict.keys() calculated_to_match = calculated_period_dict.keys()
aggregated_to_match = aggregated_period_dict.keys() aggregated_to_match = aggregated_period_dict.keys()
match_dict = {} match_dict = {}
......
...@@ -824,7 +824,7 @@ class TemplateTool (BaseTool): ...@@ -824,7 +824,7 @@ class TemplateTool (BaseTool):
repository = repository, **property_dict) repository = repository, **property_dict)
obj.setUid(uid) obj.setUid(uid)
template_list.append(obj) template_list.append(obj)
template_list.sort(lambda x,y:cmp(x.getTitle(), y.getTitle())) template_list.sort(key=lambda x: x.getTitle())
return template_list return template_list
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
......
...@@ -67,7 +67,7 @@ class CacheFactory(XMLObject): ...@@ -67,7 +67,7 @@ class CacheFactory(XMLObject):
""" get ordered list of installed cache plugins in ZODB """ """ get ordered list of installed cache plugins in ZODB """
cache_plugins = self.objectValues(self.allowed_types) cache_plugins = self.objectValues(self.allowed_types)
cache_plugins = map(None, cache_plugins) cache_plugins = map(None, cache_plugins)
cache_plugins.sort(lambda x,y: cmp(x.getIntIndex(0), y.getIntIndex(0))) cache_plugins.sort(key=lambda x: x.getIntIndex(0))
return cache_plugins return cache_plugins
security.declareProtected(Permissions.AccessContentsInformation, 'getRamCacheFactory') security.declareProtected(Permissions.AccessContentsInformation, 'getRamCacheFactory')
......
...@@ -199,7 +199,7 @@ def Folder_asXML(object, ident=0): ...@@ -199,7 +199,7 @@ def Folder_asXML(object, ident=0):
xml = xml[:xml.rfind('</object>')] xml = xml[:xml.rfind('</object>')]
# Make sure the list of sub objects is ordered # Make sure the list of sub objects is ordered
object_value_list = list(self.objectValues()) object_value_list = list(self.objectValues())
object_value_list.sort(lambda x, y: cmp(x.getId(), y.getId())) object_value_list.sort(key=lambda x: x.getId())
# Append to the xml the xml of subobjects # Append to the xml the xml of subobjects
for o in object_value_list: for o in object_value_list:
aq_ob = aq_base(o) aq_ob = aq_base(o)
......
...@@ -50,7 +50,7 @@ class OrderedPickler(Pickler): ...@@ -50,7 +50,7 @@ class OrderedPickler(Pickler):
self.memoize(obj) self.memoize(obj)
item_list = obj.items() # New version by JPS for sorting item_list = obj.items() # New version by JPS for sorting
item_list.sort(lambda a, b: cmp(a[0], b[0])) # New version by JPS for sorting item_list.sort(key=lambda x: x[0]) # New version by JPS for sorting
self._batch_setitems(item_list.__iter__()) self._batch_setitems(item_list.__iter__())
dispatch[DictionaryType] = save_dict dispatch[DictionaryType] = save_dict
...@@ -160,7 +160,7 @@ def exportXML(jar, oid, file=None): ...@@ -160,7 +160,7 @@ def exportXML(jar, oid, file=None):
new_oidict[oid] = getattr(o, 'id', None) new_oidict[oid] = getattr(o, 'id', None)
except: except:
new_oidict[oid] = None # Ick, a broken reference new_oidict[oid] = None # Ick, a broken reference
new_oids.sort(lambda a,b: cmp(new_oidict[a], new_oidict[b])) new_oids.sort(key=lambda x: new_oidict[x])
# Build new sorted oids # Build new sorted oids
oids = list(old_oids) + new_oids oids = list(old_oids) + new_oids
# Do real export # Do real export
......
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