mirror of https://github.com/python/cpython
Issue #19369: Optimized the usage of __length_hint__().
This commit is contained in:
parent
8b150ecfc9
commit
f740d467bf
|
@ -10,6 +10,8 @@ Projected release date: 2013-11-24
|
||||||
Core and Builtins
|
Core and Builtins
|
||||||
-----------------
|
-----------------
|
||||||
|
|
||||||
|
- Issue #19369: Optimized the usage of __length_hint__().
|
||||||
|
|
||||||
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
|
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
|
||||||
Python executable and not removed by the linker's optimizer.
|
Python executable and not removed by the linker's optimizer.
|
||||||
|
|
||||||
|
|
|
@ -82,15 +82,17 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
|
||||||
PyObject *hint, *result;
|
PyObject *hint, *result;
|
||||||
Py_ssize_t res;
|
Py_ssize_t res;
|
||||||
_Py_IDENTIFIER(__length_hint__);
|
_Py_IDENTIFIER(__length_hint__);
|
||||||
res = PyObject_Length(o);
|
if (_PyObject_HasLen(o)) {
|
||||||
if (res < 0 && PyErr_Occurred()) {
|
res = PyObject_Length(o);
|
||||||
if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
|
if (res < 0 && PyErr_Occurred()) {
|
||||||
return -1;
|
if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
PyErr_Clear();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
PyErr_Clear();
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
|
hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
|
||||||
if (hint == NULL) {
|
if (hint == NULL) {
|
||||||
|
|
Loading…
Reference in New Issue