mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
gh-126703: Add freelists for list and tuple iterators (GH-128592)
This commit is contained in:
parent
41ad2bb248
commit
1a80214f11
5 changed files with 24 additions and 12 deletions
|
@ -993,7 +993,8 @@ tupleiter_dealloc(PyObject *self)
|
|||
_PyTupleIterObject *it = _PyTupleIterObject_CAST(self);
|
||||
_PyObject_GC_UNTRACK(it);
|
||||
Py_XDECREF(it->it_seq);
|
||||
PyObject_GC_Del(it);
|
||||
assert(Py_IS_TYPE(self, &PyTupleIter_Type));
|
||||
_Py_FREELIST_FREE(tuple_iters, it, PyObject_GC_Del);
|
||||
}
|
||||
|
||||
static int
|
||||
|
@ -1119,15 +1120,16 @@ PyTypeObject PyTupleIter_Type = {
|
|||
static PyObject *
|
||||
tuple_iter(PyObject *seq)
|
||||
{
|
||||
_PyTupleIterObject *it;
|
||||
|
||||
if (!PyTuple_Check(seq)) {
|
||||
PyErr_BadInternalCall();
|
||||
return NULL;
|
||||
}
|
||||
it = PyObject_GC_New(_PyTupleIterObject, &PyTupleIter_Type);
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
_PyTupleIterObject *it = _Py_FREELIST_POP(_PyTupleIterObject, tuple_iters);
|
||||
if (it == NULL) {
|
||||
it = PyObject_GC_New(_PyTupleIterObject, &PyTupleIter_Type);
|
||||
if (it == NULL)
|
||||
return NULL;
|
||||
}
|
||||
it->it_index = 0;
|
||||
it->it_seq = (PyTupleObject *)Py_NewRef(seq);
|
||||
_PyObject_GC_TRACK(it);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue