Skip to content

Commit 6ba909b

Browse files
committed
Remove unnecessary calls to PyNumber_Index, PyLong_Checks
1 parent 2b195a7 commit 6ba909b

File tree

2 files changed

+6
-33
lines changed

2 files changed

+6
-33
lines changed

src_c/pixelarray.c

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1666,15 +1666,9 @@ _pxarray_subscript(pgPixelArrayObject *array, PyObject *op)
16661666
return _pxarray_subscript_internal(array, start, stop, step, 0, dim1,
16671667
1);
16681668
}
1669-
else if (PyIndex_Check(op) || PyLong_Check(op)) {
1670-
Py_ssize_t i;
1671-
PyObject *val = PyNumber_Index(op);
1672-
if (!val) {
1673-
return 0;
1674-
}
1669+
else if (PyIndex_Check(op)) {
16751670
/* A simple index. */
1676-
i = PyNumber_AsSsize_t(val, PyExc_IndexError);
1677-
Py_DECREF(val);
1671+
Py_ssize_t i = PyNumber_AsSsize_t(op, PyExc_IndexError);
16781672
if (i == -1 && PyErr_Occurred()) {
16791673
return 0;
16801674
}
@@ -1828,15 +1822,9 @@ _pxarray_ass_subscript(pgPixelArrayObject *array, PyObject *op,
18281822
Py_DECREF(tmparray);
18291823
return retval;
18301824
}
1831-
else if (PyIndex_Check(op) || PyLong_Check(op)) {
1832-
Py_ssize_t i;
1833-
PyObject *val = PyNumber_Index(op);
1834-
if (!val) {
1835-
return -1;
1836-
}
1825+
else if (PyIndex_Check(op)) {
18371826
/* A simple index. */
1838-
i = PyNumber_AsSsize_t(val, PyExc_IndexError);
1839-
Py_DECREF(val);
1827+
Py_ssize_t i = PyNumber_AsSsize_t(op, PyExc_IndexError);
18401828
if (i == -1 && PyErr_Occurred()) {
18411829
return -1;
18421830
}

src_c/rect_impl.h

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,14 +2160,7 @@ RectExport_subscript(RectObject *self, PyObject *op)
21602160
PrimitiveType *data = (PrimitiveType *)&self->r;
21612161

21622162
if (PyIndex_Check(op)) {
2163-
PyObject *index = PyNumber_Index(op);
2164-
Py_ssize_t i;
2165-
2166-
if (index == NULL) {
2167-
return NULL;
2168-
}
2169-
i = PyNumber_AsSsize_t(index, NULL);
2170-
Py_DECREF(index);
2163+
Py_ssize_t i = PyNumber_AsSsize_t(op, NULL);
21712164
return RectExport_item(self, i);
21722165
}
21732166
else if (op == Py_Ellipsis) {
@@ -2213,15 +2206,7 @@ RectExport_assSubscript(RectObject *self, PyObject *op, PyObject *value)
22132206
return -1;
22142207
}
22152208
if (PyIndex_Check(op)) {
2216-
PyObject *index;
2217-
Py_ssize_t i;
2218-
2219-
index = PyNumber_Index(op);
2220-
if (index == NULL) {
2221-
return -1;
2222-
}
2223-
i = PyNumber_AsSsize_t(index, NULL);
2224-
Py_DECREF(index);
2209+
Py_ssize_t i = PyNumber_AsSsize_t(op, NULL);
22252210
return RectExport_assItem(self, i, value);
22262211
}
22272212
else if (op == Py_Ellipsis) {

0 commit comments

Comments
 (0)