[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Benjamin Peterson
Benjamin Peterson added the comment: On Wed, Apr 29, 2015, at 13:25, Sergey B Kirpichev wrote: Sergey B Kirpichev added the comment: On Wed, Apr 29, 2015 at 03:25:19PM +, Benjamin Peterson wrote: So, basically you need a base case for recursion? What's wrong with explicitly writing

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Paul Moore
Paul Moore added the comment: I think the documentation is fine: The key corresponding to each item in the list is calculated once and then used for the entire sorting process. This corresponds with the standard decorate-sort-undecorate approach to handling key functions in sorts. It's a

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Paul Moore
Paul Moore added the comment: On 29 April 2015 at 19:42, Sergey B Kirpichev rep...@bugs.python.org wrote: It's a common computer science technique Could you provide any language that avoid this optimization? Here is Perl 5: http://perl5.git.perl.org/perl.git/blob/HEAD:/pp_sort.c#l367

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: On Wed, Apr 29, 2015 at 03:25:19PM +, Benjamin Peterson wrote: So, basically you need a base case for recursion? What's wrong with explicitly writing that out? Because it's complex (and costly). This is not a trivial test and I don't see reasons to

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: On Wed, Apr 29, 2015 at 05:44:22PM +, Paul Moore wrote: I think the documentation is fine: The key corresponding to each item in the list is calculated once and then used for the entire sorting process. Does any sorting process make sense for

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
Changes by Sergey B Kirpichev skirpic...@gmail.com: Added file: http://bugs.python.org/file39232/0001-list.sort-Add-quick-exit-if-length-of-list-1.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: On Wed, Apr 29, 2015 at 06:51:21PM +, Paul Moore wrote: But that's a sort without a key. Why it does matter? It have quick exit. For same reasons - Python could... In Perl you do a key sort via: That's just your implementation. But we could add

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
New submission from Sergey B Kirpichev: If there is nothing to sort (i.e. one item), why call key function at all? In my practical situation, simplest key() function will lead to recursion in case of such trivial lists. I can make similar cmp-type function (i.e. mycmp=lambda a, b:

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: The patch is ok for me, -- nosy: +matrixise, r.david.murray ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075 ___

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: should I add a regression test? If so, where? ./Lib/test/test_sort.py? -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075 ___

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Raymond Hettinger
Raymond Hettinger added the comment: FWIW, I don't think this is worth special casing. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075 ___

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Serhiy Storchaka
Changes by Serhiy Storchaka storch...@gmail.com: -- nosy: +rhettinger, tim.peters stage: - patch review type: behavior - performance versions: -Python 2.7, Python 3.2, Python 3.3, Python 3.4, Python 3.6 ___ Python tracker rep...@bugs.python.org

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Benjamin Peterson
Benjamin Peterson added the comment: Why does your key function depend on the size of the list? That seems like the root of the problem. Considering calling the key function is observable behavior, I don't think this should be changed. The patch makes behavior list.sort() inconsistent.

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Stéphane Wirtel
Stéphane Wirtel added the comment: Yep, add a regression test. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075 ___ ___ Python-bugs-list

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Benjamin Peterson
Benjamin Peterson added the comment: On Wed, Apr 29, 2015, at 11:03, Sergey B Kirpichev wrote: Sergey B Kirpichev added the comment: On Wed, Apr 29, 2015 at 02:32:34PM +, Benjamin Peterson wrote: Why does your key function depend on the size of the list? Because it's a real life.

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Mark Dickinson
Mark Dickinson added the comment: I should also clarify that Raymond and Mark and responsible for maintaining most of the algorithmic/data structure code in Python. Well, Raymond at least. I plead not guilty; I think you're confusing me with someone else. :-) But for this issue, this

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Mark Dickinson
Mark Dickinson added the comment: Considering calling the key function is observable behavior, I don't think this should be changed. +1 -- nosy: +mark.dickinson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Benjamin Peterson
Changes by Benjamin Peterson benja...@python.org: -- resolution: - rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue24075 ___

[issue24075] list.sort() should do quick exit if len(list) = 1

2015-04-29 Thread Sergey B Kirpichev
Sergey B Kirpichev added the comment: On Wed, Apr 29, 2015 at 02:32:34PM +, Benjamin Peterson wrote: Why does your key function depend on the size of the list? Because it's a real life. Here is the code: https://github.com/skirpichev/omg/blob/gruntz-use-subs/sympy/series/gruntz.py#L337