gh-111138: Add PyList_Extend() and PyList_Clear() functions (#111862)

* Split list_extend() into two sub-functions: list_extend_fast() and
  list_extend_iter().
* list_inplace_concat() no longer has to call Py_DECREF() on the
  list_extend() result, since list_extend() now returns an int.
This commit is contained in:
Victor Stinner 2023-11-13 17:14:56 +01:00 committed by GitHub
parent 29af7369db
commit babb787047
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 305 additions and 129 deletions

View file

@ -50,22 +50,22 @@ exit:
return return_value;
}
PyDoc_STRVAR(list_clear__doc__,
PyDoc_STRVAR(py_list_clear__doc__,
"clear($self, /)\n"
"--\n"
"\n"
"Remove all items from list.");
#define LIST_CLEAR_METHODDEF \
{"clear", (PyCFunction)list_clear, METH_NOARGS, list_clear__doc__},
#define PY_LIST_CLEAR_METHODDEF \
{"clear", (PyCFunction)py_list_clear, METH_NOARGS, py_list_clear__doc__},
static PyObject *
list_clear_impl(PyListObject *self);
py_list_clear_impl(PyListObject *self);
static PyObject *
list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
py_list_clear(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list_clear_impl(self);
return py_list_clear_impl(self);
}
PyDoc_STRVAR(list_copy__doc__,
@ -95,14 +95,14 @@ PyDoc_STRVAR(list_append__doc__,
#define LIST_APPEND_METHODDEF \
{"append", (PyCFunction)list_append, METH_O, list_append__doc__},
PyDoc_STRVAR(list_extend__doc__,
PyDoc_STRVAR(py_list_extend__doc__,
"extend($self, iterable, /)\n"
"--\n"
"\n"
"Extend list by appending elements from the iterable.");
#define LIST_EXTEND_METHODDEF \
{"extend", (PyCFunction)list_extend, METH_O, list_extend__doc__},
#define PY_LIST_EXTEND_METHODDEF \
{"extend", (PyCFunction)py_list_extend, METH_O, py_list_extend__doc__},
PyDoc_STRVAR(list_pop__doc__,
"pop($self, index=-1, /)\n"
@ -384,4 +384,4 @@ list___reversed__(PyListObject *self, PyObject *Py_UNUSED(ignored))
{
return list___reversed___impl(self);
}
/*[clinic end generated code: output=5dea9dd3bb219a7f input=a9049054013a1b77]*/
/*[clinic end generated code: output=f2d7b63119464ff4 input=a9049054013a1b77]*/