Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
try a different optimization
  • Loading branch information
kraih committed Dec 6, 2015
1 parent bc13366 commit 1fecf69
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions Changes
@@ -1,5 +1,6 @@

6.36 2015-12-06
- Improved Mojo::JSON performance slightly. (haarg)

6.35 2015-12-04
- Removed deprecated collecting method from Mojo::UserAgent::CookieJar.
Expand Down
7 changes: 4 additions & 3 deletions lib/Mojo/JSON.pm
@@ -1,7 +1,6 @@
package Mojo::JSON;
use Mojo::Base -strict;

use B;
use Carp 'croak';
use Exporter 'import';
use JSON::PP ();
Expand Down Expand Up @@ -249,9 +248,11 @@ sub _encode_value {
# Null
return 'null' unless defined $value;

# Number
# Number (bitwise operators change behavior based on the internal value type)
my $check = (my $dummy = "0") & $value;
return $value
if B::svref_2object(\$value)->FLAGS & (B::SVp_IOK | B::SVp_NOK)
if !($check ^ $check)
&& length $check
&& 0 + $value eq $value
&& $value * 0 == 0;

Expand Down

0 comments on commit 1fecf69

Please sign in to comment.