Core and Builtins
-----------------
+- Issue #19369: Optimized the usage of __length_hint__().
+
- Issue #18603: Ensure that PyOS_mystricmp and PyOS_mystrnicmp are in the
Python executable and not removed by the linker's optimizer.
PyObject *hint, *result;
Py_ssize_t res;
_Py_IDENTIFIER(__length_hint__);
- res = PyObject_Length(o);
- if (res < 0 && PyErr_Occurred()) {
- if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
- return -1;
+ if (_PyObject_HasLen(o)) {
+ res = PyObject_Length(o);
+ if (res < 0 && PyErr_Occurred()) {
+ if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
+ return -1;
+ }
+ PyErr_Clear();
+ }
+ else {
+ return res;
}
- PyErr_Clear();
- }
- else {
- return res;
}
hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
if (hint == NULL) {