diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2024-05-21 14:42:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-21 14:42:22 (GMT) |
commit | dcb8030c535343973c963814ad7b1ffe60751453 (patch) | |
tree | b0fe41b511ff2735284ff2d4a56b79c12e7b541d /Objects | |
parent | 1929b7e2bfdb5d2d789ffe19c9bf6b9fc41f3fbc (diff) | |
download | cpython-dcb8030c535343973c963814ad7b1ffe60751453.zip cpython-dcb8030c535343973c963814ad7b1ffe60751453.tar.gz cpython-dcb8030c535343973c963814ad7b1ffe60751453.tar.bz2 |
[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 ab4263a82abe8b684d8ad1edf7c7c6ec286ff756)
Co-authored-by: Donghee Na <donghee.na@python.org>
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/listobject.c | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index 7070165..d09bb63 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -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; @@ -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; } |