Skip to content

Commit

Permalink
no need to copy value for number detection
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 13, 2014
1 parent acee2b3 commit b1423f2
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions lib/Mojo/JSON.pm
Expand Up @@ -263,12 +263,10 @@ sub _encode_value {
return 'null' unless defined $value;

# Number
if (B::svref_2object(\$value)->FLAGS & (B::SVp_IOK | B::SVp_NOK)) {
no warnings 'numeric';
my $num = $value;
$num += 0;
return $num if $num eq $value && $num * 0 == 0;
}
return $value
if B::svref_2object(\$value)->FLAGS & (B::SVp_IOK | B::SVp_NOK)
&& 0 + $value eq $value
&& $value * 0 == 0;

# String
return _encode_string($value);
Expand Down

0 comments on commit b1423f2

Please sign in to comment.