Skip to content

Commit 3074926

Browse files
committed
use specific function
1 parent 1b40ba6 commit 3074926

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

Include/internal/pycore_list.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ extern "C" {
1313
#endif
1414

1515
PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
16-
PyAPI_FUNC(PyObject) *_PyList_Subscript(PyObject*, PyObject*);
16+
PyAPI_FUNC(PyObject) *_PyList_SliceSubscript(PyObject*, PyObject*);
1717
extern void _PyList_DebugMallocStats(FILE *out);
1818
// _PyList_GetItemRef should be used only when the object is known as a list
1919
// because it doesn't raise TypeError when the object is not a list, whereas PyList_GetItemRef does.

Objects/listobject.c

+23-8
Original file line numberDiff line numberDiff line change
@@ -3523,9 +3523,10 @@ list___sizeof___impl(PyListObject *self)
35233523
}
35243524

35253525
static PyObject *list_iter(PyObject *seq);
3526+
static PyObject *list_subscript(PyObject*, PyObject*);
35263527

35273528
static PyMethodDef list_methods[] = {
3528-
{"__getitem__", _PyList_Subscript, METH_O|METH_COEXIST,
3529+
{"__getitem__", list_subscript, METH_O|METH_COEXIST,
35293530
PyDoc_STR("__getitem__($self, index, /)\n--\n\nReturn self[index].")},
35303531
LIST___REVERSED___METHODDEF
35313532
LIST___SIZEOF___METHODDEF
@@ -3596,8 +3597,26 @@ list_slice_wrap(PyListObject *aa, Py_ssize_t start, Py_ssize_t stop, Py_ssize_t
35963597
return res;
35973598
}
35983599

3600+
static inline PyObject*
3601+
list_slice_subscript(PyObject* self, PyObject* item)
3602+
{
3603+
assert(PyList_Check(self));
3604+
assert(PySlice_Check(item));
3605+
Py_ssize_t start, stop, step;
3606+
if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
3607+
return NULL;
3608+
}
3609+
return list_slice_wrap((PyListObject *)self, start, stop, step);
3610+
}
3611+
35993612
PyObject *
3600-
_PyList_Subscript(PyObject* _self, PyObject* item)
3613+
_PyList_SliceSubscript(PyObject* _self, PyObject* item)
3614+
{
3615+
return list_slice_subscript(_self, item);
3616+
}
3617+
3618+
static PyObject *
3619+
list_subscript(PyObject* _self, PyObject* item)
36013620
{
36023621
PyListObject* self = (PyListObject*)_self;
36033622
if (_PyIndex_Check(item)) {
@@ -3610,11 +3629,7 @@ _PyList_Subscript(PyObject* _self, PyObject* item)
36103629
return list_item((PyObject *)self, i);
36113630
}
36123631
else if (PySlice_Check(item)) {
3613-
Py_ssize_t start, stop, step;
3614-
if (PySlice_Unpack(item, &start, &stop, &step) < 0) {
3615-
return NULL;
3616-
}
3617-
return list_slice_wrap(self, start, stop, step);
3632+
return list_slice_subscript(_self, item);
36183633
}
36193634
else {
36203635
PyErr_Format(PyExc_TypeError,
@@ -3830,7 +3845,7 @@ list_ass_subscript(PyObject *self, PyObject *item, PyObject *value)
38303845

38313846
static PyMappingMethods list_as_mapping = {
38323847
list_length,
3833-
_PyList_Subscript,
3848+
list_subscript,
38343849
list_ass_subscript
38353850
};
38363851

Python/bytecodes.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ dummy_func(
915915
assert(PySlice_Check(sub));
916916
assert(PyList_CheckExact(list));
917917

918-
PyObject *res_o = _PyList_Subscript(list, sub);
918+
PyObject *res_o = _PyList_SliceSubscript(list, sub);
919919
DEOPT_IF(res_o == NULL);
920920
STAT_INC(BINARY_OP, hit);
921921
res = PyStackRef_FromPyObjectSteal(res_o);

Python/executor_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/generated_cases.c.h

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)