Commit ef1b88bf authored by Sergey Fedoseev's avatar Sergey Fedoseev Committed by Serhiy Storchaka

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

parent d9bc543c
......@@ -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);
}
......
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