-
-
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
Changes from 1 commit
7602879
39a8757
ab450b3
717ca67
b678442
b40bd62
3837486
b6ff7ce
e7f8c46
0a6c8ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2679,7 +2679,7 @@ list___init___impl(PyListObject *self, PyObject *iterable) | |
| if (_PyObject_HasLen(iterable)) { | ||
| Py_ssize_t iter_len = PyObject_Size(iterable); | ||
| if (iter_len == -1) { | ||
| if (!PyErr_ExceptionMatches(PyExc_Exception)) { | ||
| if (!PyErr_ExceptionMatches(PyExc_TypeError)) { | ||
| return -1; | ||
| } | ||
| PyErr_Clear(); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pablogsal, @serhiy-storchaka: In a previous comment, I proposed to add an helper function to "probe" an object size: so move this code into a private helper function. Since the same code is used by PyObject_LengthHint(), it would now make sense, no? See also iter_len() ... which is different.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This code will be used just in two places and is not too complex. Adding yet one intermediate function will add a performance penalty for calling a function and checking its result, and will complicate the code. If this code will be used in more places, it can be refactored. |
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.