Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.13] gh-119053: Implement the fast path for list.__getitem__ (gh-119112) #119309

Merged
merged 1 commit into from
May 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ list_item_impl(PyListObject *self, Py_ssize_t idx)
if (!valid_index(idx, size)) {
goto exit;
}
#ifdef Py_GIL_DISABLED
item = _Py_NewRefWithLock(self->ob_item[idx]);
#else
item = Py_NewRef(self->ob_item[idx]);
#endif
exit:
Py_END_CRITICAL_SECTION();
return item;
Expand Down Expand Up @@ -656,14 +660,15 @@ list_item(PyObject *aa, Py_ssize_t i)
return NULL;
}
PyObject *item;
Py_BEGIN_CRITICAL_SECTION(a);
#ifdef Py_GIL_DISABLED
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
_PyObject_GC_SET_SHARED(a);
item = list_get_item_ref(a, i);
if (item == NULL) {
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
return NULL;
}
#endif
#else
item = Py_NewRef(a->ob_item[i]);
Py_END_CRITICAL_SECTION();
#endif
return item;
}

Expand Down
Loading