New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize `isinstance(obj, bool)` to PyBool_Check #2690

Open
jbrockmendel opened this Issue Oct 27, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@jbrockmendel

jbrockmendel commented Oct 27, 2018

I thought this was already done, but I get marginally less verbose code if I substitute in PyBool_Check myself:

+274:         if isinstance(val, bool):
    __pyx_t_6 = ((PyObject*)&PyBool_Type);
    __Pyx_INCREF(__pyx_t_6);
    __pyx_t_12 = PyObject_IsInstance(__pyx_v_val, __pyx_t_6); if (unlikely(__pyx_t_12 == ((int)-1))) __PYX_ERR(0, 274, __pyx_L1_error)
    __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0;
    __pyx_t_13 = (__pyx_t_12 != 0);
    if (__pyx_t_13) {
/* … */
      goto __pyx_L7;
    }
274:         if PyBool_Check(val):
    __pyx_t_12 = (PyBool_Check(__pyx_v_val) != 0);
    if (__pyx_t_12) {
/* … */
      goto __pyx_L7;
    }
@scoder

This comment has been minimized.

Contributor

scoder commented Oct 27, 2018

bool is currently excluded from the builtin types because it can conflict with the C++ bool data type (see Builtin.py). The missing optimisation in Optimize.py (look for _isinstance) is a side-effect of this. We should make it a normal builtin type again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment