-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
bpo-33234 Improve list() pre-sizing for inputs with known lengths (no __length_hint__) #9846
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
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7602879
Improve list() pre-sizing for inputs with known lengths
pablogsal 39a8757
Preallocate only when __len__ is available to avoid loss of performan…
pablogsal ab450b3
Fix NEWS entry and correct style
pablogsal 717ca67
Use _PyObject_HasLen to check if the object has lenght to avoid overhead
pablogsal b678442
Simplify implementation and don't capture all expections on error
pablogsal b40bd62
Add assert and fix formatting
pablogsal 3837486
Remove uneeded test modification
pablogsal b6ff7ce
Don't preallocate if list is modified when calling PyObject_Size
pablogsal e7f8c46
Improve readability in the error handling branch
pablogsal 0a6c8ba
Capture only TypeError as suggested by Serhiy
pablogsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix NEWS entry and correct style
- Loading branch information
commit ab450b3d5a453f36a4988d83b391a79bfbfa5a61
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
Misc/NEWS.d/next/Core and Builtins/2018-04-17-01-24-51.bpo-33234.l9IDtp.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| The list constructor will pre-size and not over-allocate when the input size | ||
| is known or can be reasonably estimated. | ||
| The list constructor will pre-size and not over-allocate when | ||
| the input lenght is known. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To reduce or avoid the overhead of the worst case, you can avoid this call if _PyObject_HasLen() is false.
This change doesn't require to implement a new _PyObject_ProbeLength().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated run of first experiment using
_PyObject_HasLen():