Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Speed up string parsing around 100 times

The problem was that the Match.caps is using sort(), which is quite slow
which  becomes annoying when you have over 1000 json strings in your
json file.

Kudos to jnthn++ for figuring this out.
  • Loading branch information...
commit bca5efa76e300bb9c2d07ab287ee1224a5e9e4a2 1 parent 81d8026
@tadzik tadzik authored
Showing with 2 additions and 2 deletions.
  1. +1 −1  lib/JSON/Tiny/Actions.pm
  2. +1 −1  lib/JSON/Tiny/Grammar.pm
View
2  lib/JSON/Tiny/Actions.pm
@@ -23,7 +23,7 @@ method array($/) {
}
method string($/) {
- make join '', $/.caps>>.value>>.ast
+ make join '', $0.list.map({ (.<str> || .<str_escape>).ast });
}
method value:sym<number>($/) { make eval $/.Str }
method value:sym<string>($/) { make $<string>.ast }
View
2  lib/JSON/Tiny/Grammar.pm
@@ -22,7 +22,7 @@ token value:sym<array> { <array> };
token value:sym<string> { <string> }
token string {
- \" ~ \" [ <str> | \\ <str_escape> ]*
+ \" ~ \" ( <str> | \\ <str_escape> )*
}
token str {
Please sign in to comment.
Something went wrong with that request. Please try again.