Subject: | Potential for optimizing looks_like_int() |
Currently the check in looks_like_int() looks like this:
$l==1 || $l==2 || $l==9 || $l==10 || $l==4352
However, the most common return values from looks_like_number($int) seem to be:
looks_like_number(1); # 4352
looks_like_number(-1); # 4352
looks_like_number("1"); # 1
looks_like_number("-1"); # 9
Getting 2 or 10 to appear is a challenge. Swapping the tests around to put the most likely values up front makes the sub about 20% faster overall:
$l==4352 || $l==1 || $l==9 || $l==2 || $l==10
That said, this is even faster:
sub looks_like_int {
$_[0] =~ /\A-?[0-9]+\z/;
}