Issue #19369: Optimized the usage of __length_hint__().
diff --git a/Objects/abstract.c b/Objects/abstract.c
index d937892..6c7a6cd 100644
--- a/Objects/abstract.c
+++ b/Objects/abstract.c
@@ -82,15 +82,17 @@
     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();
         }
-        PyErr_Clear();
-    }
-    else {
-        return res;
+        else {
+            return res;
+        }
     }
     hint = _PyObject_LookupSpecial(o, &PyId___length_hint__);
     if (hint == NULL) {