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.
This commit is contained in:
Raymond Hettinger 2007-12-06 00:56:53 +00:00
parent 923ad7a948
commit 4e2f714031
5 changed files with 48 additions and 86 deletions

View file

@ -794,17 +794,7 @@ listextend(PyListObject *self, PyObject *b)
iternext = *it->ob_type->tp_iternext;
/* Guess a result list size. */
n = _PyObject_LengthHint(b);
if (n < 0) {
if (PyErr_Occurred()
&& !PyErr_ExceptionMatches(PyExc_TypeError)
&& !PyErr_ExceptionMatches(PyExc_AttributeError)) {
Py_DECREF(it);
return NULL;
}
PyErr_Clear();
n = 8; /* arbitrary */
}
n = _PyObject_LengthHint(b, 8);
m = Py_Size(self);
mn = m + n;
if (mn >= m) {