]> granicus.if.org Git - python/commitdiff
binary_op1(), ternary_op(): rearrange the code so that slotw is tested
authorGuido van Rossum <guido@python.org>
Mon, 1 Oct 2001 17:10:18 +0000 (17:10 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 1 Oct 2001 17:10:18 +0000 (17:10 +0000)
(to see whether __rop__ should go before __op__) only when slotv is
set.  This saves a test+branch when only slotw is set.

Objects/abstract.c

index 7a5305ad892dbb5c58483db370e6c102cac0b6f1..4891622a72252e644a60369a0c54a4a5f243f3f6 100644 (file)
@@ -332,14 +332,14 @@ binary_op1(PyObject *v, PyObject *w, const int op_slot)
                if (slotw == slotv)
                        slotw = NULL;
        }
-       if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
-               x = slotw(v, w);
-               if (x != Py_NotImplemented)
-                       return x;
-               Py_DECREF(x); /* can't do it */
-               slotw = NULL;
-       }
        if (slotv) {
+               if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
+                       x = slotw(v, w);
+                       if (x != Py_NotImplemented)
+                               return x;
+                       Py_DECREF(x); /* can't do it */
+                       slotw = NULL;
+               }
                x = slotv(v, w);
                if (x != Py_NotImplemented)
                        return x;
@@ -442,14 +442,14 @@ ternary_op(PyObject *v,
                if (slotw == slotv)
                        slotw = NULL;
        }
-       if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
-               x = slotw(v, w, z);
-               if (x != Py_NotImplemented)
-                       return x;
-               Py_DECREF(x); /* can't do it */
-               slotw = NULL;
-       }
        if (slotv) {
+               if (slotw && PyType_IsSubtype(w->ob_type, v->ob_type)) {
+                       x = slotw(v, w, z);
+                       if (x != Py_NotImplemented)
+                               return x;
+                       Py_DECREF(x); /* can't do it */
+                       slotw = NULL;
+               }
                x = slotv(v, w, z);
                if (x != Py_NotImplemented)
                        return x;