8000 gh-94603: micro optimize list.pop by eendebakpt · Pull Request #94604 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-94603: micro optimize list.pop #94604

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 17 commits into from
Dec 27, 2022
Merged
Changes from 1 commit
Commits
8000 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
rename to size_after_pop
  • Loading branch information
eendebakpt committed Dec 26, 2022
commit 7c6c9fa0f441e65aad6037fc7705514ffaec0940
14 changes: 7 additions & 7 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -1025,23 +1025,23 @@ list_pop_impl(PyListObject *self, Py_ssize_t index)

PyObject **items = self->ob_item;
v = items[index];
Py_ssize_t pop_after_size = Py_SIZE(self) - 1;
if(pop_after_size == 0) {
Py_ssize_t size_after_pop = Py_SIZE(self) - 1;
if(size_after_pop == 0) {
Py_INCREF(v);
status = _list_clear(self);
}
else {
if ((pop_after_size - index) > 0) {
memmove(&items[index], &items[index+1], (pop_after_size - index) * sizeof(PyObject *));
if ((size_after_pop - index) > 0) {
memmove(&items[index], &items[index+1], (size_after_pop - index) * sizeof(PyObject *));
}
status = list_resize(self, Py_SIZE(self) - 1);
status = list_resize(self, size_after_pop);
}
if (status >= 0) {
return v; // and v now owns the reference the list had
return v; // and v now owns the reference the list had
}
else {
// list resize failed, need to restore
memmove(&items[index+1], &items[index], (pop_after_size - index)* sizeof(PyObject *));
memmove(&items[index+1], &items[index], (size_after_pop - index)* sizeof(PyObject *));
items[index] = v;
return NULL;
}
Expand Down
0