Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
corona10 merged 17 commits intopython:mainfromeendebakpt:performance/list_pop
Dec 27, 2022
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
Show all changes
17 commits
Select commitHold shift + click to select a range
79ac0ff
optimize list.pop
eendebakptJul 6, 2022
4cf3c19
📜🤖 Added by blurb_it.
blurb-it[bot]Jul 6, 2022
4db7ec5
fix news item
eendebakptJul 6, 2022
1512885
Update Objects/listobject.c
eendebakptJul 8, 2022
58e38d6
Update Objects/listobject.c
eendebakptJul 10, 2022
e55907c
Merge branch 'main' into performance/list_pop
eendebakptJul 26, 2022
a97f93e
Merge branch 'main' into performance/list_pop
eendebakptJul 28, 2022
a711050
Merge branch 'main' into performance/list_pop
eendebakptAug 10, 2022
b1ebb5c
Merge branch 'main' into performance/list_pop
eendebakptAug 22, 2022
12411a9
Merge branch 'main' into performance/list_pop
eendebakptSep 19, 2022
8940af7
Merge branch 'main' into performance/list_pop
eendebakptOct 19, 2022
9635cfe
Merge branch 'main' into performance/list_pop
eendebakptNov 9, 2022
91afa40
Merge branch 'main' into performance/list_pop
eendebakptDec 22, 2022
44a4efe
Apply suggestions from code review
eendebakptDec 26, 2022
7c6c9fa
rename to size_after_pop
eendebakptDec 26, 2022
7c1a835
make variable const
eendebakptDec 26, 2022
23eb3aa
Update Objects/listobject.c
corona10Dec 27, 2022
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
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Improve performance of ``list.pop`` for small lists.
32 changes: 20 additions & 12 deletionsObjects/listobject.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1022,21 +1022,29 @@ list_pop_impl(PyListObject *self, Py_ssize_t index)
PyErr_SetString(PyExc_IndexError, "pop index out of range");
return NULL;
}
v = self->ob_item[index];
if (index == Py_SIZE(self) - 1) {
status = list_resize(self, Py_SIZE(self) - 1);
if (status >= 0)
return v; /* and v now owns the reference the list had */
else
return NULL;

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

/* Reverse a slice of a list in place, from lo up to (exclusive) hi. */
Expand Down

[8]ページ先頭

©2009-2026 Movatter.jp