summaryrefslogtreecommitdiff
path: root/Objects/tupleobject.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-06-23 16:40:40 +0200
committerGitHub <noreply@github.com>2020-06-23 16:40:40 +0200
commit522691c46e2ae51faaad5bbbce7d959dd61770df (patch)
treeb6f833b6712837379d135d56125b9f3fe0dc4fa0 /Objects/tupleobject.c
parentbc43f6e21244f31d25896875430174cd4ac7604c (diff)
downloadcpython-git-522691c46e2ae51faaad5bbbce7d959dd61770df.tar.gz
bpo-40521: Cleanup code of free lists (GH-21082)
Add get_xxx_state() function to factorize duplicated code.
Diffstat (limited to 'Objects/tupleobject.c')
-rw-r--r--Objects/tupleobject.c34
1 files changed, 18 insertions, 16 deletions
diff --git a/Objects/tupleobject.c b/Objects/tupleobject.c
index 2ff4c48111..f4f9aa259e 100644
--- a/Objects/tupleobject.c
+++ b/Objects/tupleobject.c
@@ -14,19 +14,28 @@ class tuple "PyTupleObject *" "&PyTuple_Type"
#include "clinic/tupleobject.c.h"
+
+static struct _Py_tuple_state *
+get_tuple_state(void)
+{
+ PyInterpreterState *interp = _PyInterpreterState_GET();
+ return &interp->tuple;
+}
+
+
static inline void
tuple_gc_track(PyTupleObject *op)
{
_PyObject_GC_TRACK(op);
}
+
/* Print summary info about the state of the optimized allocator */
void
_PyTuple_DebugMallocStats(FILE *out)
{
#if PyTuple_MAXSAVESIZE > 0
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
for (int i = 1; i < PyTuple_MAXSAVESIZE; i++) {
char buf[128];
PyOS_snprintf(buf, sizeof(buf),
@@ -89,8 +98,7 @@ PyTuple_New(Py_ssize_t size)
{
PyTupleObject *op;
#if PyTuple_MAXSAVESIZE > 0
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
if (size == 0 && state->free_list[0]) {
op = state->free_list[0];
Py_INCREF(op);
@@ -198,8 +206,7 @@ PyTuple_Pack(Py_ssize_t n, ...)
return PyTuple_New(0);
}
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
va_start(vargs, n);
PyTupleObject *result = tuple_alloc(state, n);
@@ -233,8 +240,7 @@ tupledealloc(PyTupleObject *op)
Py_XDECREF(op->ob_item[i]);
}
#if PyTuple_MAXSAVESIZE > 0
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
#ifdef Py_DEBUG
// tupledealloc() must not be called after _PyTuple_Fini()
assert(state->numfree[0] != -1);
@@ -420,8 +426,7 @@ _PyTuple_FromArray(PyObject *const *src, Py_ssize_t n)
return PyTuple_New(0);
}
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
PyTupleObject *tuple = tuple_alloc(state, n);
if (tuple == NULL) {
return NULL;
@@ -492,8 +497,7 @@ tupleconcat(PyTupleObject *a, PyObject *bb)
return PyTuple_New(0);
}
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
np = tuple_alloc(state, size);
if (np == NULL) {
return NULL;
@@ -537,8 +541,7 @@ tuplerepeat(PyTupleObject *a, Py_ssize_t n)
if (n > PY_SSIZE_T_MAX / Py_SIZE(a))
return PyErr_NoMemory();
size = Py_SIZE(a) * n;
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
np = tuple_alloc(state, size);
if (np == NULL)
return NULL;
@@ -804,8 +807,7 @@ tuplesubscript(PyTupleObject* self, PyObject* item)
return (PyObject *)self;
}
else {
- PyInterpreterState *interp = _PyInterpreterState_GET();
- struct _Py_tuple_state *state = &interp->tuple;
+ struct _Py_tuple_state *state = get_tuple_state();
PyTupleObject* result = tuple_alloc(state, slicelength);
if (!result) return NULL;