Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit dcb8030

Browse filesBrowse files
[3.13] gh-119053: Implement the fast path for list.__getitem__ (gh-119112) (gh-119309)
gh-119053: Implement the fast path for list.__getitem__ (gh-119112) (cherry picked from commit ab4263a) Co-authored-by: Donghee Na <donghee.na@python.org>
1 parent 1929b7e commit dcb8030
Copy full SHA for dcb8030

File tree

1 file changed

+10
-5
lines changed
Filter options

1 file changed

+10
-5
lines changed

‎Objects/listobject.c

Copy file name to clipboardExpand all lines: Objects/listobject.c
+10-5Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ list_item_impl(PyListObject *self, Py_ssize_t idx)
351351
if (!valid_index(idx, size)) {
352352
goto exit;
353353
}
354+
#ifdef Py_GIL_DISABLED
355+
item = _Py_NewRefWithLock(self->ob_item[idx]);
356+
#else
354357
item = Py_NewRef(self->ob_item[idx]);
358+
#endif
355359
exit:
356360
Py_END_CRITICAL_SECTION();
357361
return item;
@@ -656,14 +660,15 @@ list_item(PyObject *aa, Py_ssize_t i)
656660
return NULL;
657661
}
658662
PyObject *item;
659-
Py_BEGIN_CRITICAL_SECTION(a);
660663
#ifdef Py_GIL_DISABLED
661-
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
662-
_PyObject_GC_SET_SHARED(a);
664+
item = list_get_item_ref(a, i);
665+
if (item == NULL) {
666+
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
667+
return NULL;
663668
}
664-
#endif
669+
#else
665670
item = Py_NewRef(a->ob_item[i]);
666-
Py_END_CRITICAL_SECTION();
671+
#endif
667672
return item;
668673
}
669674

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.