Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
use bitwise ops rather than B to check for numeric flags #2
This abuses the fact that bitwise ops change behavior based on the
We first us an & to shorten the input, so we don't end up operating on a
"0" & 0 -> 0
0 ^ 0 -> 0 (false)
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.
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)