Skip to content
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...
1 parent 81d8026 commit bca5efa76e300bb9c2d07ab287ee1224a5e9e4a2 @tadzik tadzik committed Mar 7, 2011
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 {

0 comments on commit bca5efa

Please sign in to comment.
Something went wrong with that request. Please try again.