Skip to content
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

@haarg
Copy link
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 3 commits 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)
daoswald added a commit that referenced this pull request Dec 6, 2015
use bitwise ops rather than B to check for numeric flags
@daoswald daoswald merged commit 2702483 into daoswald:master Dec 6, 2015
@daoswald
Copy link
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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.