diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-10-10-19-20-24.bpo-38436.LfVbc-.rst b/Misc/NEWS.d/next/Core and Builtins/2019-10-10-19-20-24.bpo-38436.LfVbc-.rst new file mode 100644 index 00000000000000..de7aa3fa4443ae --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2019-10-10-19-20-24.bpo-38436.LfVbc-.rst @@ -0,0 +1 @@ +Improved the performance of repeated/literal :class:`list` addition. \ No newline at end of file diff --git a/Python/ceval.c b/Python/ceval.c index a7d2ea80069a06..453c5367279774 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1551,6 +1551,11 @@ _PyEval_EvalFrameDefault(PyFrameObject *f, int throwflag) sum = unicode_concatenate(tstate, left, right, f, next_instr); /* unicode_concatenate consumed the ref to left */ } + else if (PyList_CheckExact(left) && PyList_CheckExact(right) + && Py_REFCNT(left) == 1) { + sum = PySequence_InPlaceConcat(left, right); + Py_DECREF(left); + } else { sum = PyNumber_Add(left, right); Py_DECREF(left);