Mercurial > cpython-lru_cache-weakref
diff Python/bltinmodule.c @ 44193:44c090c74202 legacy-trunk
Fix Issue 1045.
Factor-out common calling code by simplifying the length_hint API.
Speed-up the function by caching the PyObject_String for the attribute lookup.
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Thu, 06 Dec 2007 00:56:53 +0000 |
| parents | 35da915adedc |
| children | 9a976a6ee936 |
line wrap: on
line diff
--- a/Python/bltinmodule.c Thu Dec 06 00:24:23 2007 +0000 +++ b/Python/bltinmodule.c Thu Dec 06 00:56:53 2007 +0000 @@ -236,15 +236,7 @@ goto Fail_arg; /* Guess a result list size. */ - len = _PyObject_LengthHint(seq); - if (len < 0) { - if (!PyErr_ExceptionMatches(PyExc_TypeError) && - !PyErr_ExceptionMatches(PyExc_AttributeError)) { - goto Fail_it; - } - PyErr_Clear(); - len = 8; /* arbitrary */ - } + len = _PyObject_LengthHint(seq, 8); /* Get a result list. */ if (PyList_Check(seq) && seq->ob_refcnt == 1) { @@ -905,15 +897,7 @@ } /* Update len. */ - curlen = _PyObject_LengthHint(curseq); - if (curlen < 0) { - if (!PyErr_ExceptionMatches(PyExc_TypeError) && - !PyErr_ExceptionMatches(PyExc_AttributeError)) { - goto Fail_2; - } - PyErr_Clear(); - curlen = 8; /* arbitrary */ - } + curlen = _PyObject_LengthHint(curseq, 8); if (curlen > len) len = curlen; } @@ -2243,13 +2227,8 @@ len = -1; /* unknown */ for (i = 0; i < itemsize; ++i) { PyObject *item = PyTuple_GET_ITEM(args, i); - Py_ssize_t thislen = _PyObject_LengthHint(item); + Py_ssize_t thislen = _PyObject_LengthHint(item, -1); if (thislen < 0) { - if (!PyErr_ExceptionMatches(PyExc_TypeError) && - !PyErr_ExceptionMatches(PyExc_AttributeError)) { - return NULL; - } - PyErr_Clear(); len = -1; break; }
