Skip to content
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

Remove unnecessary calls to PyNumber_Index, PyLong_Checks #3242

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 4 additions & 16 deletions src_c/pixelarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -1666,15 +1666,9 @@ _pxarray_subscript(pgPixelArrayObject *array, PyObject *op)
return _pxarray_subscript_internal(array, start, stop, step, 0, dim1,
1);
}
else if (PyIndex_Check(op) || PyLong_Check(op)) {
Py_ssize_t i;
PyObject *val = PyNumber_Index(op);
if (!val) {
return 0;
}
else if (PyIndex_Check(op)) {
/* A simple index. */
i = PyNumber_AsSsize_t(val, PyExc_IndexError);
Py_DECREF(val);
Py_ssize_t i = PyNumber_AsSsize_t(op, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return 0;
}
Expand Down Expand Up @@ -1828,15 +1822,9 @@ _pxarray_ass_subscript(pgPixelArrayObject *array, PyObject *op,
Py_DECREF(tmparray);
return retval;
}
else if (PyIndex_Check(op) || PyLong_Check(op)) {
Py_ssize_t i;
PyObject *val = PyNumber_Index(op);
if (!val) {
return -1;
}
else if (PyIndex_Check(op)) {
/* A simple index. */
i = PyNumber_AsSsize_t(val, PyExc_IndexError);
Py_DECREF(val);
Py_ssize_t i = PyNumber_AsSsize_t(op, PyExc_IndexError);
if (i == -1 && PyErr_Occurred()) {
return -1;
}
Expand Down
17 changes: 4 additions & 13 deletions src_c/rect_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2160,14 +2160,10 @@ RectExport_subscript(RectObject *self, PyObject *op)
PrimitiveType *data = (PrimitiveType *)&self->r;

if (PyIndex_Check(op)) {
PyObject *index = PyNumber_Index(op);
Py_ssize_t i;

if (index == NULL) {
Py_ssize_t i = PyNumber_AsSsize_t(op, NULL);
if (i == -1 && PyErr_Occurred()) {
return NULL;
}
i = PyNumber_AsSsize_t(index, NULL);
Py_DECREF(index);
return RectExport_item(self, i);
}
else if (op == Py_Ellipsis) {
Expand Down Expand Up @@ -2213,15 +2209,10 @@ RectExport_assSubscript(RectObject *self, PyObject *op, PyObject *value)
return -1;
}
if (PyIndex_Check(op)) {
PyObject *index;
Py_ssize_t i;

index = PyNumber_Index(op);
if (index == NULL) {
Py_ssize_t i = PyNumber_AsSsize_t(op, NULL);
Starbuck5 marked this conversation as resolved.
Show resolved Hide resolved
if (i == -1 && PyErr_Occurred()) {
return -1;
}
i = PyNumber_AsSsize_t(index, NULL);
Py_DECREF(index);
return RectExport_assItem(self, i, value);
}
else if (op == Py_Ellipsis) {
Expand Down
Loading