mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
bpo-40521: Cleanup code of free lists (GH-21082)
Add get_xxx_state() function to factorize duplicated code.
This commit is contained in:
parent
bc43f6e212
commit
522691c46e
8 changed files with 110 additions and 69 deletions
|
|
@ -113,27 +113,35 @@ void _PySlice_Fini(PyThreadState *tstate)
|
|||
PyObject *
|
||||
PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
||||
{
|
||||
if (step == NULL) {
|
||||
step = Py_None;
|
||||
}
|
||||
if (start == NULL) {
|
||||
start = Py_None;
|
||||
}
|
||||
if (stop == NULL) {
|
||||
stop = Py_None;
|
||||
}
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
PySliceObject *obj;
|
||||
if (interp->slice_cache != NULL) {
|
||||
obj = interp->slice_cache;
|
||||
interp->slice_cache = NULL;
|
||||
_Py_NewReference((PyObject *)obj);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
|
||||
if (obj == NULL)
|
||||
if (obj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (step == NULL) step = Py_None;
|
||||
Py_INCREF(step);
|
||||
if (start == NULL) start = Py_None;
|
||||
Py_INCREF(start);
|
||||
if (stop == NULL) stop = Py_None;
|
||||
Py_INCREF(stop);
|
||||
|
||||
obj->step = step;
|
||||
Py_INCREF(start);
|
||||
obj->start = start;
|
||||
Py_INCREF(stop);
|
||||
obj->stop = stop;
|
||||
|
||||
_PyObject_GC_TRACK(obj);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue