Commits

illume committed a331cb9

Replaced IntFromObj function with something smaller.

"Even though youd think PyInt_AsLong would only work with PyInt's it
actually converts any type that supports the PyNumber protocol into an
in. - so theres no advantage in using PyNumber_Int.

the code below is from base.c, a smaller replacement for IntFromObj is
below. This avoids creating and removing a PyObject every time."

Thanks Campbell Barton

Comments (0)

Files changed (1)

 
 /* internal C API utility functions */
 static int
-IntFromObj (PyObject* obj, int* val)
-{
-    PyObject* intobj;
-
-    if (PyNumber_Check (obj))
+IntFromObj (PyObject* obj, int* val) {
+    int tmp_val;
+    tmp_val = PyInt_AsLong (obj);
+    if (tmp_val == -1 && PyErr_Occurred ())
     {
-        if (!(intobj = PyNumber_Int (obj)))
-        {
-            PyErr_Clear ();
-            return 0;
-        }
-        *val = PyInt_AsLong (intobj);
-        Py_DECREF (intobj);
-        if (PyErr_Occurred ())
-        {
-            PyErr_Clear ();
-            return 0;
-        }
-        return 1;
+        PyErr_Clear ();
+        return 0;
     }
-    return 0;
+    *val = tmp_val;
+    return 1;
 }
 
 static int