Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 31343:0c1d2062dee3 legacy-trunk
Apply map/zip 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 08:54:44 +0000 |
| parents | c06b570adf12 |
| children | bb3c3c98cc1b |
line wrap: on
line diff
--- a/Python/bltinmodule.c Sun Jan 04 06:08:16 2004 +0000 +++ b/Python/bltinmodule.c Sun Jan 04 08:54:44 2004 +0000 @@ -791,17 +791,13 @@ } /* Update len. */ - curlen = -1; /* unknown */ - if (PySequence_Check(curseq) && - curseq->ob_type->tp_as_sequence->sq_length) { - curlen = PySequence_Size(curseq); - if (curlen < 0) - PyErr_Clear(); + curlen = PyObject_Size(curseq); + if (curlen < 0) { + PyErr_Clear(); + curlen = 8; /* arbitrary */ } - if (curlen < 0) - curlen = 8; /* arbitrary */ - if (curlen > len) - len = curlen; + if (curlen > len) + len = curlen; } /* Get space for the result list. */ @@ -1968,7 +1964,7 @@ len = -1; /* unknown */ for (i = 0; i < itemsize; ++i) { PyObject *item = PyTuple_GET_ITEM(args, i); - int thislen = PySequence_Length(item); + int thislen = PyObject_Size(item); if (thislen < 0) { PyErr_Clear(); len = -1;
