From a0ea7a116ce52a178c02d42b684089758bd7f355 Mon Sep 17 00:00:00 2001 From: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> Date: Fri, 1 Apr 2022 06:23:42 -0400 Subject: bpo-47009: Streamline list.append for the common case (GH-31864) --- Python/ceval.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'Python/ceval.c') diff --git a/Python/ceval.c b/Python/ceval.c index 8f73ea1c01..8c1f21b086 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -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); -- cgit v1.2.1