Skip to content

Commit

Permalink
improved number detection performance
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed May 12, 2014
1 parent b125143 commit 9934604
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/Mojo/JSON.pm
Expand Up @@ -263,11 +263,12 @@ sub _encode_value {
return 'null' unless defined $value;

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

# String
return _encode_string($value);
Expand Down

0 comments on commit 9934604

Please sign in to comment.