-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
gh-145192: Improve performance of PySequence_GetSlice #145193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
569002d
66c1209
3b09eec
d7b0367
bdd742c
38c9de5
4500d45
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Improve performance of :c:func:`PySequence_GetSlice`. | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,7 @@ PyObject _Py_EllipsisObject = _PyObject_HEAD_INIT(&PyEllipsis_Type); | |
| */ | ||
|
|
||
| static PySliceObject * | ||
| _PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step) | ||
| _PyBuildSlice_Consume3(PyObject *start, PyObject *stop, PyObject *step) | ||
|
||
| { | ||
| assert(start != NULL && stop != NULL && step != NULL); | ||
| PySliceObject *obj = _Py_FREELIST_POP(PySliceObject, slices); | ||
|
|
@@ -131,13 +131,14 @@ _PyBuildSlice_Consume2(PyObject *start, PyObject *stop, PyObject *step) | |
|
|
||
| obj->start = start; | ||
| obj->stop = stop; | ||
| obj->step = Py_NewRef(step); | ||
| obj->step = step; | ||
|
|
||
| _PyObject_GC_TRACK(obj); | ||
| return obj; | ||
| error: | ||
| Py_DECREF(start); | ||
| Py_DECREF(stop); | ||
| Py_DECREF(step); | ||
| return NULL; | ||
| } | ||
|
|
||
|
|
@@ -153,15 +154,15 @@ PySlice_New(PyObject *start, PyObject *stop, PyObject *step) | |
| if (stop == NULL) { | ||
| stop = Py_None; | ||
| } | ||
| return (PyObject *)_PyBuildSlice_Consume2(Py_NewRef(start), | ||
| Py_NewRef(stop), step); | ||
| return (PyObject *)_PyBuildSlice_Consume3(Py_NewRef(start), | ||
| Py_NewRef(stop), Py_NewRef(step)); | ||
| } | ||
|
|
||
| PyObject * | ||
| _PyBuildSlice_ConsumeRefs(PyObject *start, PyObject *stop) | ||
| { | ||
| assert(start != NULL && stop != NULL); | ||
| return (PyObject *)_PyBuildSlice_Consume2(start, stop, Py_None); | ||
| return (PyObject *)_PyBuildSlice_Consume3(start, stop, Py_None); | ||
| } | ||
|
|
||
| PyObject * | ||
|
|
@@ -177,9 +178,7 @@ _PySlice_FromIndices(Py_ssize_t istart, Py_ssize_t istop) | |
| return NULL; | ||
| } | ||
|
|
||
| slice = PySlice_New(start, end, NULL); | ||
| Py_DECREF(start); | ||
| Py_DECREF(end); | ||
| slice = _PyBuildSlice_ConsumeRefs(start, end); | ||
| return slice; | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.