bpo-47009: Streamline list.append for the common case (GH-31864)

This commit is contained in:
Dennis Sweeney 2022-04-01 06:23:42 -04:00 committed by GitHub
parent f877b40e3f
commit a0ea7a116c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 27 deletions

View file

@ -2213,10 +2213,7 @@ handle_eval_breaker:
TARGET(LIST_APPEND) {
PyObject *v = POP();
PyObject *list = PEEK(oparg);
int err;
err = PyList_Append(list, v);
Py_DECREF(v);
if (err != 0)
if (_PyList_AppendTakeRef((PyListObject *)list, v) < 0)
goto error;
PREDICT(JUMP_BACKWARD_QUICK);
DISPATCH();
@ -5044,14 +5041,12 @@ handle_eval_breaker:
DEOPT_IF(!PyList_Check(list), PRECALL);
STAT_INC(PRECALL, hit);
SKIP_CALL();
PyObject *arg = TOP();
int err = PyList_Append(list, arg);
if (err) {
PyObject *arg = POP();
if (_PyList_AppendTakeRef((PyListObject *)list, arg) < 0) {
goto error;
}
Py_DECREF(arg);
Py_DECREF(list);
STACK_SHRINK(2);
STACK_SHRINK(1);
Py_INCREF(Py_None);
SET_TOP(Py_None);
Py_DECREF(callable);