8000 bpo-39829: Optimize __len__() being called twice in the list() constructor by thatbirdguythatuknownot · Pull Request #31816 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-39829: Optimize __len__() being called twice in the list() constructor #31816

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 15 commits into from
Mar 14, 2022
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
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
bpo-39829: __len__ called twice in the list() constructor
  • Loading branch information
thatbirdguythatuknownot authored Mar 10, 2022
commit b5841b9010429c6f435504a10c80c8c15c88cc89
5 changes: 3 additions & 2 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,9 @@ list_extend(PyListObject *self, PyObject *iterable)
* eventually run out of memory during the loop.
*/
}
else if (n && self->ob_item == NULL) {
if (list_preallocate_exact(self, n) < 0)
else if (self->ob_item == NULL) {
/* We have to rely on n being correct in this case. */
if (n && list_preallocate_exact(self, n) < 0)
goto error;
}
else {
Expand Down
0