Commit 16a4e2b6 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@23919 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e01be3ae
...@@ -9,22 +9,10 @@ ...@@ -9,22 +9,10 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>Script_magic</string> </key> <key> <string>Script_magic</string> </key>
<value> <int>3</int> </value> <value> <int>3</int> </value>
</item> </item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_bind_names</string> </key> <key> <string>_bind_names</string> </key>
<value> <value>
...@@ -164,13 +152,11 @@ for transaction in transaction_list:\n ...@@ -164,13 +152,11 @@ for transaction in transaction_list:\n
filter = {\'portal_type\' : context.getPortalAccountingMovementTypeList()})\n filter = {\'portal_type\' : context.getPortalAccountingMovementTypeList()})\n
\n \n
if we_are_source :\n if we_are_source :\n
transaction_lines.sort(lambda x,y: cmp(\n transaction_lines.sort(key=lambda x: x.getObject().getSourceInventoriatedTotalAssetPrice(),\n
y.getObject().getSourceInventoriatedTotalAssetPrice(),\n reverse=True)\n
x.getObject().getSourceInventoriatedTotalAssetPrice()))\n
else :\n else :\n
transaction_lines.sort(lambda x,y: cmp(\n transaction_lines.sort(key=lambda x: x.getObject().getDestinationInventoriatedTotalAssetPrice(),\n
y.getObject().getDestinationInventoriatedTotalAssetPrice(),\n reverse=True)\n
x.getObject().getDestinationInventoriatedTotalAssetPrice()))\n
\n \n
for line in transaction_lines:\n for line in transaction_lines:\n
line = line.getObject()\n line = line.getObject()\n
...@@ -243,12 +229,6 @@ return result + [{ "journal_total_debit" : journal_total_debit\n ...@@ -243,12 +229,6 @@ return result + [{ "journal_total_debit" : journal_total_debit\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
...@@ -313,6 +293,7 @@ return result + [{ "journal_total_debit" : journal_total_debit\n ...@@ -313,6 +293,7 @@ return result + [{ "journal_total_debit" : journal_total_debit\n
<string>unicode</string> <string>unicode</string>
<string>transaction_dict</string> <string>transaction_dict</string>
<string>transaction_lines</string> <string>transaction_lines</string>
<string>True</string>
<string>line</string> <string>line</string>
<string>debit</string> <string>debit</string>
<string>credit</string> <string>credit</string>
......
780 781
\ No newline at end of file \ No newline at end of file
...@@ -70,7 +70,7 @@ def getCurrencyItemList(include_empty=1, portal_path=""):\n ...@@ -70,7 +70,7 @@ def getCurrencyItemList(include_empty=1, portal_path=""):\n
result.append((currency.getReference() or currency.getTitleOrId(),\n result.append((currency.getReference() or currency.getTitleOrId(),\n
currency.getRelativeUrl()))\n currency.getRelativeUrl()))\n
\n \n
result.sort(lambda x,y: cmp(x[0], y[0]))\n result.sort(key=lambda x: x[0])\n
return result\n return result\n
\n \n
from Products.ERP5Type.Cache import CachingMethod\n from Products.ERP5Type.Cache import CachingMethod\n
......
...@@ -66,7 +66,7 @@ for career_step in all_career_step_list :\n ...@@ -66,7 +66,7 @@ for career_step in all_career_step_list :\n
career_step_list.append(career_step)\n career_step_list.append(career_step)\n
\n \n
# sort them by start date\n # sort them by start date\n
career_step_list.sort( lambda x, y: cmp(x.getStartDate(), y.getStartDate()) )\n career_step_list.sort(key=lambda x: x.getStartDate())\n
for career_step in career_step_list :\n for career_step in career_step_list :\n
# TODO: take the first date of the last active career range.\n # TODO: take the first date of the last active career range.\n
# for now, we only return the first one.\n # for now, we only return the first one.\n
......
432 433
\ No newline at end of file \ No newline at end of file
...@@ -101,7 +101,7 @@ for r_ticket in ticketlist: \n ...@@ -101,7 +101,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getDestinationTitle(), y.getDestinationTitle()))\n eventlist_sorted.sort(key=lambda x: x.getDestinationTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
campaign = ticket.getTitle(),\n campaign = ticket.getTitle(),\n
...@@ -145,7 +145,7 @@ for r_ticket in ticketlist: \n ...@@ -145,7 +145,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getSourceTitle(), y.getSourceTitle()))\n eventlist_sorted.sort(key=lambda x: x.getSourceTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
campaign = ticket.getTitle(),\n campaign = ticket.getTitle(),\n
......
...@@ -101,7 +101,7 @@ for r_ticket in ticketlist: \n ...@@ -101,7 +101,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getDestinationTitle(), y.getDestinationTitle()))\n eventlist_sorted.sort(key=lambda x: x.getDestinationTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
meeting = ticket.getTitle(),\n meeting = ticket.getTitle(),\n
...@@ -145,7 +145,7 @@ for r_ticket in ticketlist: \n ...@@ -145,7 +145,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getSourceTitle(), y.getSourceTitle()))\n eventlist_sorted.sort(key=lambda x: x.getSourceTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
meeting = ticket.getTitle(),\n meeting = ticket.getTitle(),\n
......
...@@ -102,7 +102,7 @@ for r_ticket in ticketlist: \n ...@@ -102,7 +102,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getDestinationTitle(), y.getDestinationTitle()))\n eventlist_sorted.sort(key=lambda x: x.getDestinationTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
sale_opportunity = ticket.getTitle(),\n sale_opportunity = ticket.getTitle(),\n
...@@ -146,7 +146,7 @@ for r_ticket in ticketlist: \n ...@@ -146,7 +146,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getSourceTitle(), y.getSourceTitle()))\n eventlist_sorted.sort(key=lambda x: x.getSourceTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
sale_opportunity = ticket.getTitle(),\n sale_opportunity = ticket.getTitle(),\n
......
...@@ -102,7 +102,7 @@ for r_ticket in ticketlist: \n ...@@ -102,7 +102,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getSourceTitle(), y.getSourceTitle()))\n eventlist_sorted.sort(key=lambda x: x.getSourceTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
support_request = ticket.getTitle(),\n support_request = ticket.getTitle(),\n
...@@ -145,7 +145,7 @@ for r_ticket in ticketlist: \n ...@@ -145,7 +145,7 @@ for r_ticket in ticketlist: \n
eventlist_sorted=[]\n eventlist_sorted=[]\n
for event in eventlist:\n for event in eventlist:\n
eventlist_sorted.append(event.getObject())\n eventlist_sorted.append(event.getObject())\n
eventlist_sorted.sort(lambda x,y: cmp(x.getDestinationTitle(), y.getDestinationTitle()))\n eventlist_sorted.sort(key=lambda x: x.getDestinationTitle())\n
for event in eventlist_sorted:\n for event in eventlist_sorted:\n
line_list.append( Object(uid=\'new_\',\n line_list.append( Object(uid=\'new_\',\n
support_request = ticket.getTitle(),\n support_request = ticket.getTitle(),\n
......
304 305
\ No newline at end of file \ No newline at end of file
...@@ -69,8 +69,7 @@ for dimension in dimension_list:\n ...@@ -69,8 +69,7 @@ for dimension in dimension_list:\n
if dimension is not None:\n if dimension is not None:\n
predicate_list = [x for x in context.contentValues(portal_type=\'Predicate\')\n predicate_list = [x for x in context.contentValues(portal_type=\'Predicate\')\n
if x.getStringIndex() == dimension ]\n if x.getStringIndex() == dimension ]\n
predicate_list.sort(lambda a,b: cmp(a.getProperty(\'int_index\', 1),\n predicate_list.sort(key=lambda x: x.getProperty(\'int_index\', 1))\n
b.getProperty(\'int_index\', 1)))\n
if len(predicate_list):\n if len(predicate_list):\n
dimension_result_list.append(predicate_list)\n dimension_result_list.append(predicate_list)\n
\n \n
......
143 144
\ No newline at end of file \ No newline at end of file
...@@ -9,22 +9,10 @@ ...@@ -9,22 +9,10 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>Script_magic</string> </key> <key> <string>Script_magic</string> </key>
<value> <int>3</int> </value> <value> <int>3</int> </value>
</item> </item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_bind_names</string> </key> <key> <string>_bind_names</string> </key>
<value> <value>
...@@ -84,7 +72,7 @@ for transformation in LazyFilter(\n ...@@ -84,7 +72,7 @@ for transformation in LazyFilter(\n
if not skip_invalidated or transformation.getProperty(\'validation_state\',\'default\') != \'invalidated\':\n if not skip_invalidated or transformation.getProperty(\'validation_state\',\'default\') != \'invalidated\':\n
result.append( (transformation.getTitle(),transformation.getRelativeUrl()) )\n result.append( (transformation.getTitle(),transformation.getRelativeUrl()) )\n
\n \n
result.sort(lambda x,y: cmp(x[0], y[0]) )\n result.sort(key=lambda x: x[0])\n
return result\n return result\n
</string> </value> </string> </value>
</item> </item>
...@@ -94,18 +82,6 @@ return result\n ...@@ -94,18 +82,6 @@ return result\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>include_empty=1, skip_invalidated=1</string> </value> <value> <string>include_empty=1, skip_invalidated=1</string> </value>
...@@ -137,7 +113,7 @@ return result\n ...@@ -137,7 +113,7 @@ return result\n
<string>include_empty</string> <string>include_empty</string>
<string>skip_invalidated</string> <string>skip_invalidated</string>
<string>_getattr_</string> <string>_getattr_</string>
<string>context</string> <string>context</string>
<string>portal</string> <string>portal</string>
<string>ZTUtils</string> <string>ZTUtils</string>
<string>LazyFilter</string> <string>LazyFilter</string>
......
384 385
\ No newline at end of file \ No newline at end of file
...@@ -67,7 +67,7 @@ for x in portal.portal_simulation.getInventoryList(\n ...@@ -67,7 +67,7 @@ for x in portal.portal_simulation.getInventoryList(\n
item_list.append((resource.getTitle(),\n item_list.append((resource.getTitle(),\n
resource.getRelativeUrl()))\n resource.getRelativeUrl()))\n
\n \n
item_list.sort(lambda a, b: cmp(a[0], b[0]))\n item_list.sort(key=lambda x: x[0])\n
return item_list\n return item_list\n
</string> </value> </string> </value>
</item> </item>
......
320 321
\ No newline at end of file \ No newline at end of file
...@@ -81,7 +81,7 @@ for task in listbox:\n ...@@ -81,7 +81,7 @@ for task in listbox:\n
task_items.append(task_dict)\n task_items.append(task_dict)\n
\n \n
# sort the requirements list by id to have the same order of the user\n # sort the requirements list by id to have the same order of the user\n
task_items.sort(lambda x, y: cmp(x[\'id\'], y[\'id\']))\n task_items.sort(key=lambda x: x[\'id\'])\n
\n \n
\n \n
\n \n
......
...@@ -86,7 +86,7 @@ for requirement_line in listbox:\n ...@@ -86,7 +86,7 @@ for requirement_line in listbox:\n
requirements_items.append(requirement)\n requirements_items.append(requirement)\n
\n \n
# sort the requirements list by id to have the same order of the user\n # sort the requirements list by id to have the same order of the user\n
requirements_items.sort(lambda x, y: cmp(x[\'id\'], y[\'id\']))\n requirements_items.sort(x=lambda x: x[\'id\'])\n
\n \n
clean_requirements = {}\n clean_requirements = {}\n
clean_requirements_key_list = [] # use a list for keys, to keep ordering\n clean_requirements_key_list = [] # use a list for keys, to keep ordering\n
......
612 613
\ No newline at end of file \ No newline at end of file
...@@ -9,22 +9,10 @@ ...@@ -9,22 +9,10 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>Script_magic</string> </key> <key> <string>Script_magic</string> </key>
<value> <int>3</int> </value> <value> <int>3</int> </value>
</item> </item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_bind_names</string> </key> <key> <string>_bind_names</string> </key>
<value> <value>
...@@ -80,7 +68,7 @@ checked_uids = portal.portal_selections\\\n ...@@ -80,7 +68,7 @@ checked_uids = portal.portal_selections\\\n
.getSelectionCheckedUidsFor(selection_name)\n .getSelectionCheckedUidsFor(selection_name)\n
getObj = portal.portal_catalog.getObject\n getObj = portal.portal_catalog.getObject\n
checked_uids_objs = [getObj(uid) for uid in checked_uids]\n checked_uids_objs = [getObj(uid) for uid in checked_uids]\n
checked_uids_objs.sort(lambda x,y:cmp(x.getId(), y.getId()))\n checked_uids_objs.sort(key=lambda x:x.getId())\n
\n \n
# we produce html for easier Selenium parsing\n # we produce html for easier Selenium parsing\n
table = "\\n".join(["<tr><td>%s</td><td>%s</td></tr>" % (\n table = "\\n".join(["<tr><td>%s</td><td>%s</td></tr>" % (\n
...@@ -103,18 +91,6 @@ return """<html>\n ...@@ -103,18 +91,6 @@ return """<html>\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>selection_name=None, **kw</string> </value> <value> <string>selection_name=None, **kw</string> </value>
......
393 394
\ No newline at end of file \ No newline at end of file
...@@ -9,22 +9,10 @@ ...@@ -9,22 +9,10 @@
</pickle> </pickle>
<pickle> <pickle>
<dictionary> <dictionary>
<item>
<key> <string>Python_magic</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>Script_magic</string> </key> <key> <string>Script_magic</string> </key>
<value> <int>3</int> </value> <value> <int>3</int> </value>
</item> </item>
<item>
<key> <string>__ac_local_roles__</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_bind_names</string> </key> <key> <string>_bind_names</string> </key>
<value> <value>
...@@ -78,8 +66,7 @@ def sortDictByValues(adict):\n ...@@ -78,8 +66,7 @@ def sortDictByValues(adict):\n
Return sorted list of tuples [(key, value),...]\n Return sorted list of tuples [(key, value),...]\n
"""\n """\n
items = adict.items()\n items = adict.items()\n
items.sort(lambda x,y: cmp(x[1], y[1]))\n items.sort(key=lambda x: x[1], reverse=True)\n
items.reverse()\n
return items\n return items\n
\n \n
def calculateStatistics():\n def calculateStatistics():\n
...@@ -160,18 +147,6 @@ return stats\n ...@@ -160,18 +147,6 @@ return stats\n
<none/> <none/>
</value> </value>
</item> </item>
<item>
<key> <string>_filepath</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>_owner</string> </key>
<value>
<none/>
</value>
</item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string></string> </value> <value> <string></string> </value>
......
709 710
\ No newline at end of file \ No newline at end of file
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