From 0af5e800014410295e31fc76655e216d9841bc34 Mon Sep 17 00:00:00 2001 From: Sergey B Kirpichev Date: Tue, 28 Apr 2015 23:01:12 +0300 Subject: [PATCH] list.sort(): Add quick exit if length of list <= 1 --- Objects/listobject.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Objects/listobject.c b/Objects/listobject.c index 45e54ce..6741826 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1938,6 +1938,9 @@ listsort(PyListObject *self, PyObject *args, PyObject *kwds) if (keyfunc == Py_None) keyfunc = NULL; + if (Py_SIZE(self) <= 1) + Py_RETURN_NONE; + /* The list is temporarily made empty, so that mutations performed * by comparison functions can't affect the slice of memory we're * sorting (allowing mutations during sorting is a core-dump -- 1.9.1