mirror of https://github.com/python/cpython
gh-119053: Implement the fast path for list.__getitem__ (gh-119112)
This commit is contained in:
parent
73f4a58d36
commit
ab4263a82a
|
@ -351,7 +351,11 @@ list_item_impl(PyListObject *self, Py_ssize_t idx)
|
||||||
if (!valid_index(idx, size)) {
|
if (!valid_index(idx, size)) {
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
#ifdef Py_GIL_DISABLED
|
||||||
|
item = _Py_NewRefWithLock(self->ob_item[idx]);
|
||||||
|
#else
|
||||||
item = Py_NewRef(self->ob_item[idx]);
|
item = Py_NewRef(self->ob_item[idx]);
|
||||||
|
#endif
|
||||||
exit:
|
exit:
|
||||||
Py_END_CRITICAL_SECTION();
|
Py_END_CRITICAL_SECTION();
|
||||||
return item;
|
return item;
|
||||||
|
@ -656,14 +660,15 @@ list_item(PyObject *aa, Py_ssize_t i)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
PyObject *item;
|
PyObject *item;
|
||||||
Py_BEGIN_CRITICAL_SECTION(a);
|
|
||||||
#ifdef Py_GIL_DISABLED
|
#ifdef Py_GIL_DISABLED
|
||||||
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
|
item = list_get_item_ref(a, i);
|
||||||
_PyObject_GC_SET_SHARED(a);
|
if (item == NULL) {
|
||||||
|
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#else
|
||||||
item = Py_NewRef(a->ob_item[i]);
|
item = Py_NewRef(a->ob_item[i]);
|
||||||
Py_END_CRITICAL_SECTION();
|
#endif
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue