Skip to content

Commit

Permalink
pythongh-119053: Implement the fast path for list.__getitem__
Browse files Browse the repository at this point in the history
  • Loading branch information
corona10 committed May 17, 2024
1 parent 100c7ab commit 5fb201d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,11 +651,18 @@ static PyObject *
list_item(PyObject *aa, Py_ssize_t i)
{
PyListObject *a = (PyListObject *)aa;
PyObject *item;
if (!valid_index(i, PyList_GET_SIZE(a))) {
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
return NULL;
}
PyObject *item;
#ifdef Py_GIL_DISABLED
PyObject **ob_item = _Py_atomic_load_ptr(&a->ob_item);
item = _Py_atomic_load_ptr(&ob_item[i]);
if (item && _Py_TryIncrefCompare(&ob_item[i], item)) {
return item;
}
#endif
Py_BEGIN_CRITICAL_SECTION(a);
#ifdef Py_GIL_DISABLED
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
Expand Down

0 comments on commit 5fb201d

Please sign in to comment.