mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
GH-94163: Add BINARY_SLICE and STORE_SLICE instructions. (GH-94168)
This commit is contained in:
parent
33fc3b5e42
commit
c0453a40fa
14 changed files with 339 additions and 161 deletions
|
@ -110,6 +110,37 @@ void _PySlice_Fini(PyInterpreterState *interp)
|
|||
index is present.
|
||||
*/
|
||||
|
||||
static PySliceObject *
|
||||
_PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step)
|
||||
{
|
||||
assert(start != NULL && stop != NULL && step != NULL);
|
||||
|
||||
PyInterpreterState *interp = _PyInterpreterState_GET();
|
||||
PySliceObject *obj;
|
||||
if (interp->slice_cache != NULL) {
|
||||
obj = interp->slice_cache;
|
||||
interp->slice_cache = NULL;
|
||||
_Py_NewReference((PyObject *)obj);
|
||||
}
|
||||
else {
|
||||
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
|
||||
if (obj == NULL) {
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
obj->start = start;
|
||||
obj->stop = stop;
|
||||
obj->step = Py_NewRef(step);
|
||||
|
||||
_PyObject_GC_TRACK(obj);
|
||||
return obj;
|
||||
error:
|
||||
Py_DECREF(start);
|
||||
Py_DECREF(stop);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PyObject *
|
||||
PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
||||
{
|
||||
|
@ -122,30 +153,16 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step)
|
|||
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 {
|
||||
obj = PyObject_GC_New(PySliceObject, &PySlice_Type);
|
||||
if (obj == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
Py_INCREF(step);
|
||||
obj->step = step;
|
||||
Py_INCREF(start);
|
||||
obj->start = start;
|
||||
Py_INCREF(stop);
|
||||
obj->stop = stop;
|
||||
return (PyObject *) _PyBuildSlice_Consume2(start, stop, step);
|
||||
}
|
||||
|
||||
_PyObject_GC_TRACK(obj);
|
||||
return (PyObject *) obj;
|
||||
PyObject *
|
||||
_PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop)
|
||||
{
|
||||
assert(start != NULL && stop != NULL);
|
||||
return (PyObject *)_PyBuildSlice_Consume2(start, stop, Py_None);
|
||||
}
|
||||
|
||||
PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue