From 272d4d1d630bddeebae1c6012f4a7628625dfe1b Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Mon, 11 Jul 2022 20:20:57 +0200 Subject: [PATCH 1/2] specialize for single element recycle --- Objects/listobject.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 83dfb7da01dfc3..503003d415c3cd 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -692,7 +692,11 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) goto Error; } } - memcpy(recycle, &item[ilow], s); + if (norig==1) + recycle[0] = item[ilow]; + else { + memcpy(recycle, &item[ilow], s); + } } if (d < 0) { /* Delete -d items */ From 1c459d0b4968cdbc4767d05145f3c56da902687b Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Mon, 11 Jul 2022 22:40:12 +0200 Subject: [PATCH 2/2] one more specialization --- Objects/listobject.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 503003d415c3cd..e8fe246b56a703 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -700,10 +700,16 @@ list_ass_slice(PyListObject *a, Py_ssize_t ilow, Py_ssize_t ihigh, PyObject *v) } if (d < 0) { /* Delete -d items */ - Py_ssize_t tail; - tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *); - memmove(&item[ihigh+d], &item[ihigh], tail); + if((Py_SIZE(a) - ihigh)==1) { + item[ihigh-1] = item[ihigh]; + } + else { + Py_ssize_t tail; + tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *); + memmove(&item[ihigh+d], &item[ihigh], tail); + } if (list_resize(a, Py_SIZE(a) + d) < 0) { + Py_ssize_t tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *); memmove(&item[ihigh], &item[ihigh+d], tail); memcpy(&item[ilow], recycle, s); goto Error;