From c61de4cdea396b29bf07c472e5820157bb2197e3 Mon Sep 17 00:00:00 2001 From: Pieter Eendebak Date: Tue, 2 Aug 2022 23:19:57 +0200 Subject: [PATCH] specialize for single element recycle, variant 2 --- Objects/listobject.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Objects/listobject.c b/Objects/listobject.c index 83dfb7da01dfc3..b60aa59095a9e9 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -692,13 +692,22 @@ 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 */ Py_ssize_t tail; tail = (Py_SIZE(a) - ihigh) * sizeof(PyObject *); - memmove(&item[ihigh+d], &item[ihigh], tail); + if (tail==sizeof(PyObject *)) { + item[ihigh-1] = item[ihigh]; + } + else { + memmove(&item[ihigh+d], &item[ihigh], tail); + } if (list_resize(a, Py_SIZE(a) + d) < 0) { memmove(&item[ihigh], &item[ihigh+d], tail); memcpy(&item[ilow], recycle, s);