Commit f740d467 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19369: Optimized the usage of __length_hint__().

parent 8b150ecf
...@@ -10,6 +10,8 @@ Projected release date: 2013-11-24 ...@@ -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,6 +82,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) ...@@ -82,6 +82,7 @@ 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__);
if (_PyObject_HasLen(o)) {
res = PyObject_Length(o); res = PyObject_Length(o);
if (res < 0 && PyErr_Occurred()) { if (res < 0 && PyErr_Occurred()) {
if (!PyErr_ExceptionMatches(PyExc_TypeError)) { if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
...@@ -92,6 +93,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue) ...@@ -92,6 +93,7 @@ PyObject_LengthHint(PyObject *o, Py_ssize_t defaultvalue)
else { else {
return res; return res;
} }
}
hint = _PyObject_LookupSpecial(o, &PyId___length_hint__); hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
if (hint == NULL) { if (hint == NULL) {
if (PyErr_Occurred()) { if (PyErr_Occurred()) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment