Skip to content
This repository has been archived by the owner on Dec 10, 2018. It is now read-only.

Simplify the read_i08() bool result cast. #162

Merged
merged 1 commit into from
Oct 12, 2015

Conversation

jparise
Copy link
Contributor

@jparise jparise commented Oct 10, 2015

The cython-generated code for bool(read_i08(buf)) includes a call to the
Python bool type function. That extra call is unnecessary in this case.
Instead, we can cast to cython's bint type, which generates code that
directly returns Py_True or Py_False (via __Pyx_PyBool_FromLong).

This appears to be the most efficient code generation for this expression.
For completeness, I also investigated these variants:

  • <bool>read_i08(buf)
  • read_i08(buf) != 0
  • <bool>(read_i08(buf) != 0)
  • return False if read_i08(buf) == 0 else True

The cython-generated code for `bool(read_i08(buf))` includes a call to the
Python `bool` type function. That extra call is unnecessary in this case.
Instead, we can cast to cython's `bint` type, which generates code that
directly returns `Py_True` or `Py_False` (via `__Pyx_PyBool_FromLong`).

This appears to be the most efficient code generation for this expression.
For completeness, I also investigated these variants:

    - <bool>read_i08(buf)
    - read_i08(buf) != 0
    - <bool>(read_i08(buf) != 0)
    - return False if read_i08(buf) == 0 else True
lxyu added a commit that referenced this pull request Oct 12, 2015
Simplify the read_i08() bool result cast.
@lxyu lxyu merged commit 981ec6e into Thriftpy:develop Oct 12, 2015
@lxyu
Copy link
Contributor

lxyu commented Oct 12, 2015

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants