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