diff options
author | Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com> | 2022-04-01 10:23:42 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-01 10:23:42 (GMT) |
commit | a0ea7a116ce52a178c02d42b684089758bd7f355 (patch) | |
tree | 052ce2e531b12a0f3d2f8242a8a346c0ad9dadba /Include/internal | |
parent | f877b40e3f7e0d97878884d80fbec879a85ab7e8 (diff) | |
download | cpython-a0ea7a116ce52a178c02d42b684089758bd7f355.zip cpython-a0ea7a116ce52a178c02d42b684089758bd7f355.tar.gz cpython-a0ea7a116ce52a178c02d42b684089758bd7f355.tar.bz2 |
bpo-47009: Streamline list.append for the common case (GH-31864)
Diffstat (limited to 'Include/internal')
-rw-r--r-- | Include/internal/pycore_list.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/Include/internal/pycore_list.h b/Include/internal/pycore_list.h index 0717a1f..860dce1 100644 --- a/Include/internal/pycore_list.h +++ b/Include/internal/pycore_list.h @@ -37,6 +37,24 @@ struct _Py_list_state { #define _PyList_ITEMS(op) (_PyList_CAST(op)->ob_item) +extern int +_PyList_AppendTakeRefListResize(PyListObject *self, PyObject *newitem); + +static inline int +_PyList_AppendTakeRef(PyListObject *self, PyObject *newitem) +{ + assert(self != NULL && newitem != NULL); + assert(PyList_Check(self)); + Py_ssize_t len = PyList_GET_SIZE(self); + Py_ssize_t allocated = self->allocated; + assert((size_t)len + 1 < PY_SSIZE_T_MAX); + if (allocated > len) { + PyList_SET_ITEM(self, len, newitem); + Py_SET_SIZE(self, len + 1); + return 0; + } + return _PyList_AppendTakeRefListResize(self, newitem); +} #ifdef __cplusplus } |