Skip to content

Commit

Permalink
Remove unnecessary calls to PyNumber_Index, PyLong_Checks
Browse files Browse the repository at this point in the history
  • Loading branch information
Starbuck5 committed Nov 25, 2024
1 parent 2b195a7 commit 6ba909b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 33 deletions.
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
19 changes: 2 additions & 17 deletions src_c/rect_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2160,14 +2160,7 @@ 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) {
return NULL;
}
i = PyNumber_AsSsize_t(index, NULL);
Py_DECREF(index);
Py_ssize_t i = PyNumber_AsSsize_t(op, NULL);
return RectExport_item(self, i);
}
else if (op == Py_Ellipsis) {
Expand Down Expand Up @@ -2213,15 +2206,7 @@ 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) {
return -1;
}
i = PyNumber_AsSsize_t(index, NULL);
Py_DECREF(index);
Py_ssize_t i = PyNumber_AsSsize_t(op, NULL);
return RectExport_assItem(self, i, value);
}
else if (op == Py_Ellipsis) {
Expand Down

0 comments on commit 6ba909b

Please sign in to comment.