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

use bitwise ops rather than B to check for numeric flags #2

Merged
merged 3 commits into from Dec 6, 2015

Conversation

Projects
None yet
2 participants
@haarg
Contributor

haarg commented Dec 5, 2015

This abuses the fact that bitwise ops change behavior based on the
internal type of a value. This avoids the memory cost of loading B, and
ends up being faster as well.

We first us an & to shorten the input, so we don't end up operating on a
long string.

"0" & 0 -> 0
"0" & "" -> ""
"0" & $string -> $character

0 ^ 0 -> 0 (false)
$character ^ $character -> "\x00" (true)

Previous attempts to use this technique didn't include the & step to shorten the value, and were thus slower than using B for long strings.

This is a revision of PR #1, including a fix for perl < 5.14, as well as documenting the purpose of the checks better.

haarg added some commits Dec 5, 2015

use bitwise ops rather than B to check for numeric flags
This abuses the fact that bitwise ops change behavior based on the
internal type of a value.  This avoids the memory cost of loading B, and
ends up being faster as well.

We first us an & to shorten the input, so we don't end up operating on a
long string.

"0" & 0       -> 0
"0" & ""      -> ""
"0" & $string -> $character

0 ^ 0                    -> 0 (false)
$character ^ $character  -> "\x00" (true)

daoswald added a commit that referenced this pull request Dec 6, 2015

Merge pull request #2 from haarg/bitwise
use bitwise ops rather than B to check for numeric flags

@daoswald daoswald merged commit 2702483 into daoswald:master Dec 6, 2015

@daoswald

This comment has been minimized.

Show comment
Hide comment
@daoswald

daoswald Dec 6, 2015

Owner

Merged. Thanks! I'll re-release to cpan this weekend.

Owner

daoswald commented Dec 6, 2015

Merged. Thanks! I'll re-release to cpan this weekend.

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