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.
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 8389a86..ca767da 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -794,17 +794,7 @@
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) {