]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-36062: Minor speed-up for list slicing and copying. (GH-11967)
authorSergey Fedoseev <fedoseev.sergey@gmail.com>
Thu, 21 Feb 2019 06:51:52 +0000 (11:51 +0500)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 21 Feb 2019 06:51:52 +0000 (08:51 +0200)
Objects/listobject.c

index e11a3fdd1358de94123d98672a4527115391b3fb..a08b3b50dd9add9fb2ad8b6b39d4dae289d15355 100644 (file)
@@ -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);
 }