Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ef1b88b

Browse files
sir-sigurdserhiy-storchaka
authored andcommitted
bpo-36062: Minor speed-up for list slicing and copying. (GH-11967)
1 parent d9bc543 commit ef1b88b

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

Objects/listobject.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -476,14 +476,6 @@ list_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
476476
PyListObject *np;
477477
PyObject **src, **dest;
478478
Py_ssize_t i, len;
479-
if (ilow < 0)
480-
ilow = 0;
481-
else if (ilow > Py_SIZE(a))
482-
ilow = Py_SIZE(a);
483-
if (ihigh < ilow)
484-
ihigh = ilow;
485-
else if (ihigh > Py_SIZE(a))
486-
ihigh = Py_SIZE(a);
487479
len = ihigh - ilow;
488480
np = (PyListObject *) list_new_prealloc(len);
489481
if (np == NULL)
@@ -507,6 +499,18 @@ PyList_GetSlice(PyObject *a, Py_ssize_t ilow, Py_ssize_t ihigh)
507499
PyErr_BadInternalCall();
508500
return NULL;
509501
}
502+
if (ilow < 0) {
503+
ilow = 0;
504+
}
505+
else if (ilow > Py_SIZE(a)) {
506+
ilow = Py_SIZE(a);
507+
}
508+
if (ihigh < ilow) {
509+
ihigh = ilow;
510+
}
511+
else if (ihigh > Py_SIZE(a)) {
512+
ihigh = Py_SIZE(a);
513+
}
510514
return list_slice((PyListObject *)a, ilow, ihigh);
511515
}
512516

0 commit comments

Comments
 (0)