mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
gh-111968: Use per-thread slice_cache in free-threading (gh-113972)
This commit is contained in:
parent
44e47dfba5
commit
3eae76554b
7 changed files with 28 additions and 18 deletions
|
@ -103,16 +103,20 @@ PyObject _Py_EllipsisObject = _PyObject_HEAD_INIT(&PyEllipsis_Type);
|
|||
|
||||
/* Slice object implementation */
|
||||
|
||||
|
||||
void _PySlice_Fini(PyInterpreterState *interp)
|
||||
void _PySlice_ClearCache(_PyFreeListState *state)
|
||||
{
|
||||
PySliceObject *obj = interp->slice_cache;
|
||||
PySliceObject *obj = state->slice_state.slice_cache;
|
||||
if (obj != NULL) {
|
||||
interp->slice_cache = NULL;
|
||||
state->slice_state.slice_cache = NULL;
|
||||
PyObject_GC_Del(obj);
|
||||
}
|
||||
}
|
||||
|
||||
void _PySlice_Fini(_PyFreeListState *state)
|
||||
{
|
||||
_PySlice_ClearCache(state);
|
||||
}
|
||||
|
||||
/* start, stop, and step are python objects with None indicating no
|
||||
index is present.
|
||||
*/
|
||||
|
@ -122,11 +126,11 @@ _PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
|
|||
{
|
||||
assert(start != NULL && stop != NULL && step != NULL);
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
_PyFreeListState *state = _PyFreeListState_GET();
|
||||
PySliceObject *obj;
|
||||
if (interp->slice_cache != NULL) {
|
||||
obj = interp->slice_cache;
|
||||
interp->slice_cache = NULL;
|
||||
if (state->slice_state.slice_cache != NULL) {
|
||||
obj = state->slice_state.slice_cache;
|
||||
state->slice_state.slice_cache = NULL;
|
||||
_Py_NewReference((PyObject *)obj);
|
||||
}
|
||||
else {
|
||||
|
@ -354,13 +358,13 @@ Create a slice object. This is used for extended slicing (e.g. a[0:10:2]).");
|
|||
static void
|
||||
slice_dealloc(PySliceObject *r)
|
||||
{
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
_PyFreeListState *state = _PyFreeListState_GET();
|
||||
_PyObject_GC_UNTRACK(r);
|
||||
Py_DECREF(r->step);
|
||||
Py_DECREF(r->start);
|
||||
Py_DECREF(r->stop);
|
||||
if (interp->slice_cache == NULL) {
|
||||
interp->slice_cache = r;
|
||||
if (state->slice_state.slice_cache == NULL) {
|
||||
state->slice_state.slice_cache = r;
|
||||
}
|
||||
else {
|
||||
PyObject_GC_Del(r);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue