Commit 439e26da 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@23760 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent d656716a
...@@ -368,7 +368,7 @@ class AmortisationRule(Rule): ...@@ -368,7 +368,7 @@ class AmortisationRule(Rule):
for current_dict in (aggregated_period_dict, calculated_period_dict): for current_dict in (aggregated_period_dict, calculated_period_dict):
for type_dict in current_dict.values(): for type_dict in current_dict.values():
for movement_list in type_dict.values(): for movement_list in type_dict.values():
movement_list.sort( lambda a,b: cmp(a['stop_date'], b['stop_date']) ) movement_list.sort(key=lambda x: x['stop_date'])
matched_dict = self._matchAmortisationPeriods(calculated_period_dict, aggregated_period_dict) matched_dict = self._matchAmortisationPeriods(calculated_period_dict, aggregated_period_dict)
# We can now apply the calculated movements on the applied rule # We can now apply the calculated movements on the applied rule
......
...@@ -1256,11 +1256,9 @@ class SkinTemplateItem(ObjectTemplateItem): ...@@ -1256,11 +1256,9 @@ class SkinTemplateItem(ObjectTemplateItem):
new_selection.append(skin_id) new_selection.append(skin_id)
new_selection.extend(selection) new_selection.extend(selection)
# sort the layer according to skin priorities # sort the layer according to skin priorities
new_selection.sort(lambda a, b : cmp( new_selection.sort(
b in ps.objectIds() and ps[b].getProperty( key=lambda x: x in ps.objectIds() and -ps[x].getProperty(
'business_template_skin_layer_priority', 0) or 0, 'business_template_skin_layer_priority', 0) or 0)
a in ps.objectIds() and ps[a].getProperty(
'business_template_skin_layer_priority', 0) or 0))
ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1) ps.manage_skinLayers(skinpath = tuple(new_selection), skinname = skin_name, add_skin = 1)
# Make sure that skin data is up-to-date (see CMFCore/Skinnable.py). # Make sure that skin data is up-to-date (see CMFCore/Skinnable.py).
p.changeSkin(None) p.changeSkin(None)
......
...@@ -125,11 +125,11 @@ class Container(Movement, XMLObject): ...@@ -125,11 +125,11 @@ class Container(Movement, XMLObject):
""" """
result = "" result = ""
container_line_list = list(self.objectValues()) container_line_list = list(self.objectValues())
container_line_list.sort(lambda x, y: cmp(x.getResource(), y.getResource())) container_line_list.sort(key=lambda x: x.getResource())
for container_line in container_line_list: for container_line in container_line_list:
if container_line.hasCellContent(): if container_line.hasCellContent():
container_cell_list = list(container_line.objectValues()) container_cell_list = list(container_line.objectValues())
container_cell_list.sort(lambda x, y: cmp(x.getVariationText(), y.getVariationText())) container_cell_list.sort(key=lambda x: x.getVariationText())
for container_cell in container_cell_list: for container_cell in container_cell_list:
result += "%s %s %s\n" % (container_cell.getResource(), result += "%s %s %s\n" % (container_cell.getResource(),
container_cell.getQuantity(), container_cell.getQuantity(),
...@@ -137,7 +137,7 @@ class Container(Movement, XMLObject): ...@@ -137,7 +137,7 @@ class Container(Movement, XMLObject):
else: else:
result += "%s %s\n" % (container_line.getResource(), container_line.getQuantity()) result += "%s %s\n" % (container_line.getResource(), container_line.getQuantity())
container_list = list(self.objectValues(spec = self.meta_type)) container_list = list(self.objectValues(spec = self.meta_type))
container_list.sort(lambda x, y: cmp(x.getContainerText(), y.getContainerText())) container_list.sort(key=lambda x: x.getContainerText())
more_result = "" more_result = ""
for container in container_list: for container in container_list:
more_result += container.getContainerText() more_result += container.getContainerText()
......
...@@ -266,7 +266,10 @@ class Image(File, OFSImage): ...@@ -266,7 +266,10 @@ class Image(File, OFSImage):
if id in id_list: if id in id_list:
id_list.remove(id) id_list.remove(id)
# Sort by desired photo surface area # Sort by desired photo surface area
id_list.sort(lambda x,y,d=self.getSizeFromImageDisplay: cmp(d(x)[0]*d(x)[1], d(y)[0]*d(y)[1])) def getSurfaceArea(img):
x, y = self.getSizeFromImageDisplay(img)
return x * y
id_list.sort(key=getSurfaceArea)
return id_list return id_list
security.declareProtected('Access contents information', 'displayLinks') security.declareProtected('Access contents information', 'displayLinks')
......
...@@ -76,6 +76,6 @@ class MovementGroup(XMLObject): ...@@ -76,6 +76,6 @@ class MovementGroup(XMLObject):
def separate(self, movement_list): def separate(self, movement_list):
# We sort group of simulation movements by their IDs. # We sort group of simulation movements by their IDs.
# DO NOT OVERRIDE THIS METHOD. Override _separate() instead. # DO NOT OVERRIDE THIS METHOD. Override _separate() instead.
return sorted([[sorted(x[0], lambda a,b:cmp(a.getId(), b.getId())), x[1]] \ return sorted([[sorted(x[0], key=lambda x: x.getId()), x[1]] \
for x in self._separate(movement_list)], for x in self._separate(movement_list)],
lambda a,b: cmp(a[0][0].getId(), b[0][0].getId())) lambda a,b: cmp(a[0][0].getId(), b[0][0].getId()))
...@@ -263,8 +263,7 @@ class OrderBuilder(XMLObject, Amount, Predicate): ...@@ -263,8 +263,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
original = None original = None
if original is not None: if original is not None:
original_id = original.getId() original_id = original.getId()
instance_list.sort(lambda a,b:cmp(b.getId()==original_id, instance_list.sort(key=lambda x: x.getId() != original_id and 1 or 0)
a.getId()==original_id))
for instance_to_update in instance_list: for instance_to_update in instance_list:
result, property_dict = self._test( result, property_dict = self._test(
instance_to_update, movement_group_list, divergence_list) instance_to_update, movement_group_list, divergence_list)
......
...@@ -234,6 +234,6 @@ class WebSite(WebSection): ...@@ -234,6 +234,6 @@ class WebSite(WebSection):
section_list = section_dict.values() section_list = section_dict.values()
# Sort by Index # Sort by Index
section_list.sort(lambda x,y: cmp(x.getIntIndex(), y.getIntIndex())) section_list.sort(key=lambda x: x.getIntIndex())
return section_list return section_list
...@@ -2265,7 +2265,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -2265,7 +2265,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction') c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
c_transaction_list = [o.getObject() for o in c_transaction_list] c_transaction_list = [o.getObject() for o in c_transaction_list]
c_transaction_list.sort(lambda a,b: cmp(a.getStopDate(),b.getStopDate())) c_transaction_list.sort(key=lambda x: x.getStopDate())
self._testAccountingBuild(c_transaction_list, e_transaction_list) self._testAccountingBuild(c_transaction_list, e_transaction_list)
...@@ -2298,7 +2298,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -2298,7 +2298,7 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction') c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
c_transaction_list = [o.getObject() for o in c_transaction_list] c_transaction_list = [o.getObject() for o in c_transaction_list]
#c_transaction_list.sort(lambda a,b: cmp(a.getStopDate(),b.getStopDate())) #c_transaction_list.sort(key=lambda x: x.getStopDate())
self._testAccountingBuild(c_transaction_list, e_transaction_list) self._testAccountingBuild(c_transaction_list, e_transaction_list)
...@@ -2994,9 +2994,9 @@ class TestImmobilisationMixin(ERP5TypeTestCase): ...@@ -2994,9 +2994,9 @@ class TestImmobilisationMixin(ERP5TypeTestCase):
except: except:
pass pass
if type(c_value) == type([]): if type(c_value) == type([]):
c_value.sort(lambda a,b: cmp(a.getId(), b.getId())) c_value.sort(key=lambda x: x.getId())
if type(e_value) == type([]): if type(e_value) == type([]):
e_value.sort(lambda a,b: cmp(a.getId(), b.getId())) e_value.sort(key=lambda x: x.getId())
if is_float: if is_float:
wrong_transaction = (round(c_value,2) != round(e_value,2)) wrong_transaction = (round(c_value,2) != round(e_value,2))
else: else:
......
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