Permalink
Browse files

another small optimization since we can easily know the index at whic…

…h the string escape occurs
  • Loading branch information...
1 parent 81b5b5a commit 021a21f56cf380ad8e2acde5f19f11064bb7718e @etrepum etrepum committed Sep 23, 2008
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/mochijson2.erl
View
@@ -330,8 +330,11 @@ decode_array(B, S=#decoder{state=comma}, Acc) ->
tokenize_string(B, S=#decoder{offset=O}) ->
case tokenize_string_fast(B, O) of
- null ->
- tokenize_string(B, S, []);
+ {escape, O1} ->
+ Length = O1 - O,
+ S1 = ?ADV_COL(S, Length),
+ <<_:O/binary, Head:Length/binary, _/binary>> = B,
+ tokenize_string(B, S1, lists:reverse(binary_to_list(Head)));
O1 ->
Length = O1 - O,
<<_:O/binary, String:Length/binary, ?Q, _/binary>> = B,
@@ -345,7 +348,7 @@ tokenize_string_fast(B, O) ->
<<_:O/binary, C, _/binary>> when C =/= $\\ ->
tokenize_string_fast(B, 1 + O);
_ ->
- null
+ {escape, O}
end.
tokenize_string(B, S=#decoder{offset=O}, Acc) ->

0 comments on commit 021a21f

Please sign in to comment.