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

gh-119053: Implement the fast path for list.__getitem__ #119112

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

Merged
merged 8 commits into from
May 21, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed May 18, 2024
commit 5ae49e3d75ed30218f4b7d034c3ac518f29fd84b
27 changes: 7 additions & 20 deletions 27 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 @@ -655,28 +659,11 @@ list_item(PyObject *aa, Py_ssize_t i)
PyErr_SetObject(PyExc_IndexError, &_Py_STR(list_err));
return NULL;
}
PyObject *item;
#ifdef Py_GIL_DISABLED
mpage marked this conversation as resolved.
Show resolved Hide resolved
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)) {
if (ob_item != _Py_atomic_load_ptr(&a->ob_item)) {
Py_DECREF(item);
goto retry;
}
return item;
}
retry:
#endif
Py_BEGIN_CRITICAL_SECTION(a);
#ifdef Py_GIL_DISABLED
if (!_Py_IsOwnedByCurrentThread((PyObject *)a) && !_PyObject_GC_IS_SHARED(a)) {
_PyObject_GC_SET_SHARED(a);
}
return list_get_item_ref(a, i);
mpage marked this conversation as resolved.
Show resolved Hide resolved
#else
return Py_NewRef(a->ob_item[i]);
#endif
item = Py_NewRef(a->ob_item[i]);
Py_END_CRITICAL_SECTION();
return item;
}

static PyObject *
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.