Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Small string escape optimization
  • Loading branch information
lizmat committed Jul 15, 2015
1 parent 22f7192 commit 52458b5
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/core/JSON/Pretty.pm
Expand Up @@ -37,20 +37,16 @@ my class JSONPrettyActions {

method str($/) { make ~$/ }

my %esc = '\\' => "\\",
'/' => "/",
'b' => "\b",
'n' => "\n",
't' => "\t",
'f' => "\f",
'r' => "\r",
'"' => "\"";
method str_escape($/) {
if $<xdigit> {
make chr(:16($<xdigit>.join));
} else {
my %h = '\\' => "\\",
'/' => "/",
'b' => "\b",
'n' => "\n",
't' => "\t",
'f' => "\f",
'r' => "\r",
'"' => "\"";
make %h{~$/};
}
make $<xdigit> ?? chr(:16($<xdigit>.join)) !! %esc.AT-KEY(~$/);
}
}

Expand Down

0 comments on commit 52458b5

Please sign in to comment.