Skip to content

Commit 5fb201d

Browse files
committed
gh-119053: Implement the fast path for list.__getitem__
1 parent 100c7ab commit 5fb201d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

Objects/listobject.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -651,11 +651,18 @@ static PyObject *
651651
list_item(PyObject *aa, Py_ssize_t i)
652652
{
653653
PyListObject *a = (PyListObject *)aa;
654+
PyObject *item;
654655
if (!valid_index(i, PyList_GET_SIZE(a))) {
655656
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
656657
return NULL;
657658
}
658-
PyObject *item;
659+
#ifdef Py_GIL_DISABLED
660+
PyObject **ob_item = _Py_atomic_load_ptr(&a->ob_item);
661+
item = _Py_atomic_load_ptr(&ob_item[i]);
662+
if (item && _Py_TryIncrefCompare(&ob_item[i], item)) {
663+
return item;
664+
}
665+
#endif
659666
Py_BEGIN_CRITICAL_SECTION(a);
660667
#ifdef Py_GIL_DISABLED
661668
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy