Skip to content

Commit 3264e8d

Browse files
Drop get_tuple_state().
1 parent 631d12b commit 3264e8d

File tree

1 file changed

+17
-26
lines changed

1 file changed

+17
-26
lines changed

Objects/tupleobject.c

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include "pycore_initconfig.h" // _PyStatus_OK()
88
#include "pycore_object.h" // _PyObject_GC_TRACK()
99
#include "pycore_pyerrors.h" // _Py_FatalRefcountError()
10-
#include "pycore_tuple.h" // struct _Py_tuple_state()
1110

1211
/*[clinic input]
1312
class tuple "PyTupleObject *" "&PyTuple_Type"
@@ -17,27 +16,20 @@ class tuple "PyTupleObject *" "&PyTuple_Type"
1716
#include "clinic/tupleobject.c.h"
1817

1918

20-
#if PyTuple_MAXSAVESIZE > 0
21-
static struct _Py_tuple_state *
22-
get_tuple_state(void)
23-
{
24-
PyInterpreterState *interp = _PyInterpreterState_GET();
25-
return &interp->tuple;
26-
}
27-
#endif
19+
#define STATE (interp->tuple)
2820

2921

3022
/* Print summary info about the state of the optimized allocator */
3123
void
3224
_PyTuple_DebugMallocStats(FILE *out)
3325
{
3426
#if PyTuple_MAXSAVESIZE > 0
35-
struct _Py_tuple_state *state = get_tuple_state();
27+
PyInterpreterState *interp = _PyInterpreterState_GET();
3628
for (int i = 1; i < PyTuple_MAXSAVESIZE; i++) {
3729
char buf[128];
3830
PyOS_snprintf(buf, sizeof(buf),
3931
"free %d-sized PyTupleObject", i);
40-
_PyDebugAllocatorStats(out, buf, state->numfree[i-1],
32+
_PyDebugAllocatorStats(out, buf, STATE.numfree[i-1],
4133
_PyObject_VAR_SIZE(&PyTuple_Type, i));
4234
}
4335
#endif
@@ -65,14 +57,14 @@ tuple_alloc(Py_ssize_t size)
6557

6658
// Check for max save size > 1.
6759
#if PyTuple_MAXSAVESIZE > 1
68-
struct _Py_tuple_state *state = get_tuple_state();
60+
PyInterpreterState *interp = _PyInterpreterState_GET();
6961
#ifdef Py_DEBUG
7062
// tuple_alloc() must not be called after _PyTuple_Fini()
71-
assert(state->numfree[0] >= 0);
63+
assert(STATE.numfree[0] >= 0);
7264
#endif
73-
if (size < PyTuple_MAXSAVESIZE && (op = state->free_list[size-1]) != NULL) {
74-
state->free_list[size-1] = (PyTupleObject *) op->ob_item[0];
75-
state->numfree[size-1]--;
65+
if (size < PyTuple_MAXSAVESIZE && (op = STATE.free_list[size-1]) != NULL) {
66+
STATE.free_list[size-1] = (PyTupleObject *) op->ob_item[0];
67+
STATE.numfree[size-1]--;
7668
/* Inlined _PyObject_InitVar() without _PyType_HasFeature() test */
7769
#ifdef Py_TRACE_REFS
7870
Py_SET_SIZE(op, size);
@@ -240,18 +232,18 @@ tupledealloc(PyTupleObject *op)
240232
Py_XDECREF(op->ob_item[i]);
241233
}
242234
#if PyTuple_MAXSAVESIZE > 0
243-
struct _Py_tuple_state *state = get_tuple_state();
235+
PyInterpreterState *interp = _PyInterpreterState_GET();
244236
#ifdef Py_DEBUG
245237
// tupledealloc() must not be called after _PyTuple_Fini()
246-
assert(state->numfree[0] >= 0);
238+
assert(STATE.numfree[0] >= 0);
247239
#endif
248240
if (len < (PyTuple_MAXSAVESIZE - 1)
249-
&& state->numfree[len-1] < PyTuple_MAXFREELIST
241+
&& STATE.numfree[len-1] < PyTuple_MAXFREELIST
250242
&& Py_IS_TYPE(op, &PyTuple_Type))
251243
{
252-
op->ob_item[0] = (PyObject *) state->free_list[len-1];
253-
state->numfree[len-1]++;
254-
state->free_list[len-1] = op;
244+
op->ob_item[0] = (PyObject *) STATE.free_list[len-1];
245+
STATE.numfree[len-1]++;
246+
STATE.free_list[len-1] = op;
255247
goto done; /* return */
256248
}
257249
#endif
@@ -1026,11 +1018,10 @@ void
10261018
_PyTuple_ClearFreeList(PyInterpreterState *interp)
10271019
{
10281020
#if PyTuple_MAXSAVESIZE > 0
1029-
struct _Py_tuple_state *state = &interp->tuple;
10301021
for (Py_ssize_t i = 1; i < PyTuple_MAXSAVESIZE; i++) {
1031-
PyTupleObject *p = state->free_list[i-1];
1032-
state->free_list[i-1] = NULL;
1033-
state->numfree[i-1] = 0;
1022+
PyTupleObject *p = STATE.free_list[i-1];
1023+
STATE.free_list[i-1] = NULL;
1024+
STATE.numfree[i-1] = 0;
10341025
while (p) {
10351026
PyTupleObject *q = p;
10361027
p = (PyTupleObject *)(p->ob_item[0]);

0 commit comments

Comments
 (0)