[Python-checkins] bpo-36062: Minor speed-up for list slicing and copying. (GH-11967)

Serhiy Storchaka webhook-mailer at python.org
Thu Feb 21 01:51:55 EST 2019


https://github.com/python/cpython/commit/ef1b88bf57aae93893d55f1b9c9639dbe9cc7786
commit: ef1b88bf57aae93893d55f1b9c9639dbe9cc7786
branch: master
author: Sergey Fedoseev <fedoseev.sergey at gmail.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2019-02-21T08:51:52+02:00
summary:

bpo-36062: Minor speed-up for list slicing and copying. (GH-11967)

files:
M Objects/listobject.c

diff --git a/Objects/listobject.c b/Objects/listobject.c
index e11a3fdd1358..a08b3b50dd9a 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -476,14 +476,6 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
     PyListObject *np;
     PyObject **src, **dest;
     Py_ssize_t i, len;
-    if (ilow < 0)
-        ilow = 0;
-    else if (ilow > Py_SIZE(a))
-        ilow = Py_SIZE(a);
-    if (ihigh < ilow)
-        ihigh = ilow;
-    else if (ihigh > Py_SIZE(a))
-        ihigh = Py_SIZE(a);
     len = ihigh - ilow;
     np = (PyListObject *) list_new_prealloc(len);
     if (np == NULL)
@@ -507,6 +499,18 @@ PyList_GetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
         PyErr_BadInternalCall();
         return NULL;
     }
+    if (ilow < 0) {
+        ilow = 0;
+    }
+    else if (ilow > Py_SIZE(a)) {
+        ilow = Py_SIZE(a);
+    }
+    if (ihigh < ilow) {
+        ihigh = ilow;
+    }
+    else if (ihigh > Py_SIZE(a)) {
+        ihigh = Py_SIZE(a);
+    }
     return list_slice((PyListObject *)a, ilow, ihigh);
 }
 



More information about the Python-checkins mailing list