mirror of
https://github.com/python/cpython.git
synced 2025-08-30 13:38:43 +00:00
Apply pre-sizing optimization to a broader class of objects.
Formerly, the length was only fetched from sequence objects. Now, any object that reports its length can benefit from pre-sizing.
This commit is contained in:
parent
4618cc09ec
commit
b86269db45
2 changed files with 8 additions and 16 deletions
|
@ -153,15 +153,11 @@ builtin_filter(PyObject *self, PyObject *args)
|
|||
return NULL;
|
||||
|
||||
/* Guess a result list size. */
|
||||
len = -1; /* unknown */
|
||||
if (PySequence_Check(seq) &&
|
||||
seq->ob_type->tp_as_sequence->sq_length) {
|
||||
len = PySequence_Size(seq);
|
||||
if (len < 0)
|
||||
PyErr_Clear();
|
||||
len = PyObject_Size(seq);
|
||||
if (len < 0) {
|
||||
PyErr_Clear();
|
||||
len = 8; /* arbitrary */
|
||||
}
|
||||
if (len < 0)
|
||||
len = 8; /* arbitrary */
|
||||
|
||||
/* Pre-allocate argument list tuple. */
|
||||
arg = PyTuple_New(1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue