Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 31345:bb3c3c98cc1b legacy-trunk
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.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Sun, 04 Jan 2004 11:00:08 +0000 |
| parents | 0c1d2062dee3 |
| children | 1219f1162d1d |
line wrap: on
line diff
--- a/Python/bltinmodule.c Sun Jan 04 09:58:33 2004 +0000 +++ b/Python/bltinmodule.c Sun Jan 04 11:00:08 2004 +0000 @@ -153,15 +153,11 @@ 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);
