mirror of
https://github.com/python/cpython.git
synced 2025-11-02 03:01:58 +00:00
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:
parent
923ad7a948
commit
4e2f714031
5 changed files with 48 additions and 86 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue