mirror of https://github.com/python/cpython
gh-111968: Split _Py_async_gen_asend_freelist out of _Py_async_gen_fr… (gh-115546)
This commit is contained in:
parent
318f2190bc
commit
8db8d7118e
|
@ -105,11 +105,15 @@ struct _Py_async_gen_freelist {
|
||||||
fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend
|
fragmentation, as _PyAsyncGenWrappedValue and PyAsyncGenASend
|
||||||
are short-living objects that are instantiated for every
|
are short-living objects that are instantiated for every
|
||||||
__anext__() call. */
|
__anext__() call. */
|
||||||
struct _PyAsyncGenWrappedValue* value_freelist[_PyAsyncGen_MAXFREELIST];
|
struct _PyAsyncGenWrappedValue* items[_PyAsyncGen_MAXFREELIST];
|
||||||
int value_numfree;
|
int numfree;
|
||||||
|
#endif
|
||||||
|
};
|
||||||
|
|
||||||
struct PyAsyncGenASend* asend_freelist[_PyAsyncGen_MAXFREELIST];
|
struct _Py_async_gen_asend_freelist {
|
||||||
int asend_numfree;
|
#ifdef WITH_FREELISTS
|
||||||
|
struct PyAsyncGenASend* items[_PyAsyncGen_MAXFREELIST];
|
||||||
|
int numfree;
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -129,6 +133,7 @@ struct _Py_object_freelists {
|
||||||
struct _Py_slice_freelist slices;
|
struct _Py_slice_freelist slices;
|
||||||
struct _Py_context_freelist contexts;
|
struct _Py_context_freelist contexts;
|
||||||
struct _Py_async_gen_freelist async_gens;
|
struct _Py_async_gen_freelist async_gens;
|
||||||
|
struct _Py_async_gen_asend_freelist async_gen_asends;
|
||||||
struct _Py_object_stack_freelist object_stacks;
|
struct _Py_object_stack_freelist object_stacks;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1635,6 +1635,13 @@ get_async_gen_freelist(void)
|
||||||
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
||||||
return &freelists->async_gens;
|
return &freelists->async_gens;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct _Py_async_gen_asend_freelist *
|
||||||
|
get_async_gen_asend_freelist(void)
|
||||||
|
{
|
||||||
|
struct _Py_object_freelists *freelists = _Py_object_freelists_GET();
|
||||||
|
return &freelists->async_gen_asends;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
@ -1659,25 +1666,27 @@ void
|
||||||
_PyAsyncGen_ClearFreeLists(struct _Py_object_freelists *freelist_state, int is_finalization)
|
_PyAsyncGen_ClearFreeLists(struct _Py_object_freelists *freelist_state, int is_finalization)
|
||||||
{
|
{
|
||||||
#ifdef WITH_FREELISTS
|
#ifdef WITH_FREELISTS
|
||||||
struct _Py_async_gen_freelist *state = &freelist_state->async_gens;
|
struct _Py_async_gen_freelist *freelist = &freelist_state->async_gens;
|
||||||
|
|
||||||
while (state->value_numfree > 0) {
|
while (freelist->numfree > 0) {
|
||||||
_PyAsyncGenWrappedValue *o;
|
_PyAsyncGenWrappedValue *o;
|
||||||
o = state->value_freelist[--state->value_numfree];
|
o = freelist->items[--freelist->numfree];
|
||||||
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
||||||
PyObject_GC_Del(o);
|
PyObject_GC_Del(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
while (state->asend_numfree > 0) {
|
struct _Py_async_gen_asend_freelist *asend_freelist = &freelist_state->async_gen_asends;
|
||||||
|
|
||||||
|
while (asend_freelist->numfree > 0) {
|
||||||
PyAsyncGenASend *o;
|
PyAsyncGenASend *o;
|
||||||
o = state->asend_freelist[--state->asend_numfree];
|
o = asend_freelist->items[--asend_freelist->numfree];
|
||||||
assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type));
|
assert(Py_IS_TYPE(o, &_PyAsyncGenASend_Type));
|
||||||
PyObject_GC_Del(o);
|
PyObject_GC_Del(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_finalization) {
|
if (is_finalization) {
|
||||||
state->value_numfree = -1;
|
freelist->numfree = -1;
|
||||||
state->asend_numfree = -1;
|
asend_freelist->numfree = -1;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -1726,11 +1735,11 @@ async_gen_asend_dealloc(PyAsyncGenASend *o)
|
||||||
Py_CLEAR(o->ags_gen);
|
Py_CLEAR(o->ags_gen);
|
||||||
Py_CLEAR(o->ags_sendval);
|
Py_CLEAR(o->ags_sendval);
|
||||||
#ifdef WITH_FREELISTS
|
#ifdef WITH_FREELISTS
|
||||||
struct _Py_async_gen_freelist *async_gen_freelist = get_async_gen_freelist();
|
struct _Py_async_gen_asend_freelist *freelist = get_async_gen_asend_freelist();
|
||||||
if (async_gen_freelist->asend_numfree >= 0 && async_gen_freelist->asend_numfree < _PyAsyncGen_MAXFREELIST) {
|
if (freelist->numfree >= 0 && freelist->numfree < _PyAsyncGen_MAXFREELIST) {
|
||||||
assert(PyAsyncGenASend_CheckExact(o));
|
assert(PyAsyncGenASend_CheckExact(o));
|
||||||
_PyGC_CLEAR_FINALIZED((PyObject *)o);
|
_PyGC_CLEAR_FINALIZED((PyObject *)o);
|
||||||
async_gen_freelist->asend_freelist[async_gen_freelist->asend_numfree++] = o;
|
freelist->items[freelist->numfree++] = o;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
@ -1896,10 +1905,10 @@ async_gen_asend_new(PyAsyncGenObject *gen, PyObject *sendval)
|
||||||
{
|
{
|
||||||
PyAsyncGenASend *o;
|
PyAsyncGenASend *o;
|
||||||
#ifdef WITH_FREELISTS
|
#ifdef WITH_FREELISTS
|
||||||
struct _Py_async_gen_freelist *async_gen_freelist = get_async_gen_freelist();
|
struct _Py_async_gen_asend_freelist *freelist = get_async_gen_asend_freelist();
|
||||||
if (async_gen_freelist->asend_numfree > 0) {
|
if (freelist->numfree > 0) {
|
||||||
async_gen_freelist->asend_numfree--;
|
freelist->numfree--;
|
||||||
o = async_gen_freelist->asend_freelist[async_gen_freelist->asend_numfree];
|
o = freelist->items[freelist->numfree];
|
||||||
_Py_NewReference((PyObject *)o);
|
_Py_NewReference((PyObject *)o);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1931,10 +1940,10 @@ async_gen_wrapped_val_dealloc(_PyAsyncGenWrappedValue *o)
|
||||||
_PyObject_GC_UNTRACK((PyObject *)o);
|
_PyObject_GC_UNTRACK((PyObject *)o);
|
||||||
Py_CLEAR(o->agw_val);
|
Py_CLEAR(o->agw_val);
|
||||||
#ifdef WITH_FREELISTS
|
#ifdef WITH_FREELISTS
|
||||||
struct _Py_async_gen_freelist *async_gen_freelist = get_async_gen_freelist();
|
struct _Py_async_gen_freelist *freelist = get_async_gen_freelist();
|
||||||
if (async_gen_freelist->value_numfree >= 0 && async_gen_freelist->value_numfree < _PyAsyncGen_MAXFREELIST) {
|
if (freelist->numfree >= 0 && freelist->numfree < _PyAsyncGen_MAXFREELIST) {
|
||||||
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
||||||
async_gen_freelist->value_freelist[async_gen_freelist->value_numfree++] = o;
|
freelist->items[freelist->numfree++] = o;
|
||||||
OBJECT_STAT_INC(to_freelist);
|
OBJECT_STAT_INC(to_freelist);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2004,10 +2013,10 @@ _PyAsyncGenValueWrapperNew(PyThreadState *tstate, PyObject *val)
|
||||||
assert(val);
|
assert(val);
|
||||||
|
|
||||||
#ifdef WITH_FREELISTS
|
#ifdef WITH_FREELISTS
|
||||||
struct _Py_async_gen_freelist *async_gen_freelist = get_async_gen_freelist();
|
struct _Py_async_gen_freelist *freelist = get_async_gen_freelist();
|
||||||
if (async_gen_freelist->value_numfree > 0) {
|
if (freelist->numfree > 0) {
|
||||||
async_gen_freelist->value_numfree--;
|
freelist->numfree--;
|
||||||
o = async_gen_freelist->value_freelist[async_gen_freelist->value_numfree];
|
o = freelist->items[freelist->numfree];
|
||||||
OBJECT_STAT_INC(from_freelist);
|
OBJECT_STAT_INC(from_freelist);
|
||||||
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
assert(_PyAsyncGenWrappedValue_CheckExact(o));
|
||||||
_Py_NewReference((PyObject*)o);
|
_Py_NewReference((PyObject*)o);
|
||||||
|
|
Loading…
Reference in New Issue