Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Tadeusz Sośnierz authored March 07, 2011
2  lib/JSON/Tiny/Actions.pm
@@ -23,7 +23,7 @@ method array($/) {
23 23
 }
24 24
 
25 25
 method string($/) {
26  
-    make join '', $/.caps>>.value>>.ast
  26
+    make join '', $0.list.map({ (.<str> || .<str_escape>).ast });
27 27
 }
28 28
 method value:sym<number>($/) { make eval $/.Str }
29 29
 method value:sym<string>($/) { make $<string>.ast }
2  lib/JSON/Tiny/Grammar.pm
@@ -22,7 +22,7 @@ token value:sym<array>   { <array>  };
22 22
 token value:sym<string>  { <string> }
23 23
 
24 24
 token string {
25  
-    \" ~ \" [ <str> | \\ <str_escape> ]*
  25
+    \" ~ \" ( <str> | \\ <str_escape> )*
26 26
 }
27 27
 
28 28
 token str {

0 notes on commit bca5efa

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