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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The cython-generated code for
bool(read_i08(buf))
includes a call to thePython
bool
type function. That extra call is unnecessary in this case.Instead, we can cast to cython's
bint
type, which generates code thatdirectly returns
Py_True
orPy_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