Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
improve Mojo::JSON performance slightly
  • Loading branch information
kraih committed Dec 5, 2015
1 parent 217ef4a commit 6a3268c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

6.36 2015-12-05
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 = "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 6a3268c

Please sign in to comment.