revert change from strings/keys being presented as binaries to being presented as lists of characters. ~30% speedup
This commit is contained in:
parent
20f9e0368d
commit
b3eb058463
23 changed files with 57 additions and 57 deletions
|
@ -282,10 +282,10 @@ multi_test_result() ->
|
|||
[{literal, false}],
|
||||
[{literal, null}],
|
||||
[start_object, end_object],
|
||||
[start_object, {key, <<"key">>}, {string, <<"value">>}, end_object],
|
||||
[start_object, {key, "key"}, {string, "value"}, end_object],
|
||||
[start_array, end_array],
|
||||
[start_array, {integer, 1}, {integer, 2}, {integer, 3}, end_array],
|
||||
[{string, <<"hope this works">>}]
|
||||
[{string, "hope this works"}]
|
||||
].
|
||||
|
||||
|
||||
|
|
|
@ -43,15 +43,15 @@
|
|||
| utf32
|
||||
| {utf32, little}
|
||||
}.
|
||||
|
||||
|
||||
|
||||
-type jsx_event() :: start_object
|
||||
| end_object
|
||||
| start_array
|
||||
| end_array
|
||||
| end_json
|
||||
| {key, binary()}
|
||||
| {string, binary()}
|
||||
| {key, list()}
|
||||
| {string, list()}
|
||||
| {integer, integer()}
|
||||
| {float, float()}
|
||||
| {literal, true}
|
||||
|
|
|
@ -357,11 +357,11 @@ key(Bin, Stack, Opts) ->
|
|||
string(Bin, Stack, Opts) -> string(Bin, Stack, Opts, []).
|
||||
|
||||
string(<<?quote/?utfx, Rest/binary>>, [key|_] = Stack, Opts, Acc) ->
|
||||
{jsx, {key, unicode:characters_to_binary(lists:reverse(Acc))}, fun() ->
|
||||
{jsx, {key, lists:reverse(Acc)}, fun() ->
|
||||
colon(Rest, Stack, Opts)
|
||||
end};
|
||||
string(<<?quote/?utfx, Rest/binary>>, Stack, Opts, Acc) ->
|
||||
{jsx, {string, unicode:characters_to_binary(lists:reverse(Acc))}, fun() ->
|
||||
{jsx, {string, lists:reverse(Acc)}, fun() ->
|
||||
maybe_done(Rest, Stack, Opts)
|
||||
end};
|
||||
string(<<?rsolidus/?utfx, Rest/binary>>, Stack, Opts, Acc) ->
|
||||
|
@ -1228,7 +1228,7 @@ check_bad(List) ->
|
|||
).
|
||||
|
||||
check_replaced(List) ->
|
||||
lists:dropwhile(fun({_, [{string, <<16#fffd/utf8>>}|_]}) ->
|
||||
lists:dropwhile(fun({_, [{string, [16#fffd]}|_]}) ->
|
||||
true
|
||||
; (_) ->
|
||||
false
|
||||
|
|
|
@ -163,8 +163,8 @@ collect(_, _, _) -> erlang:error(badarg).
|
|||
|
||||
|
||||
%% helper functions for converting jsx events to term format
|
||||
event({string, String}, _Opts) -> String;
|
||||
event({key, Key}, _Opts) -> Key;
|
||||
event({string, String}, _Opts) -> unicode:characters_to_binary(String);
|
||||
event({key, Key}, _Opts) -> unicode:characters_to_binary(Key);
|
||||
event({integer, Integer}, _Opts) -> Integer;
|
||||
event({float, Float}, _Opts) -> Float;
|
||||
event({literal, Literal}, _Opts) -> Literal.
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
{name, "array"}.
|
||||
{jsx, [start_array,
|
||||
{string,<<"foo">>},
|
||||
{string,<<"bar">>},
|
||||
{string,<<"baz">>},
|
||||
{string,"foo"},
|
||||
{string,"bar"},
|
||||
{string,"baz"},
|
||||
start_array,
|
||||
{literal,true},
|
||||
end_array,start_array,
|
||||
|
@ -15,14 +15,14 @@
|
|||
{literal,null},
|
||||
{float,0.7},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{string,<<"value">>},
|
||||
{key,"key"},
|
||||
{string,"value"},
|
||||
end_object,start_array,start_object,end_object,
|
||||
{literal,null},
|
||||
{literal,null},
|
||||
{literal,null},
|
||||
start_array,end_array,end_array,
|
||||
{string,<<"\n\r\\">>},
|
||||
{string,"\n\r\\"},
|
||||
start_array,
|
||||
{integer,-1},
|
||||
end_array,end_array,end_json]}.
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{name, "encoded_surrogates"}.
|
||||
{jsx, [start_array,{string,<<66560/utf8>>},end_array,end_json]}.
|
||||
{jsx, [start_array,{string,66560]},end_array,end_json]}.
|
||||
{json, "encoded_surrogates.json"}.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{name, "escaped noncharacter (extended)"}.
|
||||
{jsx, [{string, <<16#fffd/utf8>>}, end_json]}.
|
||||
{jsx, [{string, [16#fffd]}, end_json]}.
|
||||
{json, "escaped_noncharacter_ext.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
|
@ -1,4 +1,4 @@
|
|||
{name, "escaped noncharacter replacement"}.
|
||||
{jsx, [{string,<<16#fffd/utf8>>},end_json]}.
|
||||
{jsx, [{string,[16#fffd]},end_json]}.
|
||||
{json, "escaped_noncharacter_replaced.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
|
@ -1,4 +1,4 @@
|
|||
{name, "escaped nullbyte replaced"}.
|
||||
{jsx, [{string,<<16#fffd/utf8>>},end_json]}.
|
||||
{jsx, [{string,[16#fffd]},end_json]}.
|
||||
{json, "escaped_nullbyte_replaced.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
|
@ -4,9 +4,9 @@
|
|||
end_array,
|
||||
{float,2.0e7},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{key,"key"},
|
||||
{float,2.0e7},
|
||||
{key,<<"another key">>},
|
||||
{key,"another key"},
|
||||
{float,2.0e7},
|
||||
end_object,
|
||||
{float,4.2e70},
|
||||
|
|
|
@ -4,14 +4,14 @@
|
|||
end_array,
|
||||
{float,2.0},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{key,"key"},
|
||||
{float,2.0e7},
|
||||
{key,<<"another key">>},
|
||||
{key,"another key"},
|
||||
{float,2.0e7},
|
||||
end_object,start_object,
|
||||
{key,<<"key">>},
|
||||
{key,"key"},
|
||||
{float,2.0},
|
||||
{key,<<"another key">>},
|
||||
{key,"another key"},
|
||||
{float,2.0},
|
||||
end_object,
|
||||
{float,4.321},
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
end_array,
|
||||
{integer,20},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{key,"key"},
|
||||
{integer,20},
|
||||
{key,<<"another key">>},
|
||||
{key,"another key"},
|
||||
{integer,20},
|
||||
end_object,
|
||||
{integer,42},
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{name, "multibyte_utf"}.
|
||||
{jsx, [start_array,{string,<<32,119070/utf8,32>>},end_array,end_json]}.
|
||||
{jsx, [start_array,{string,[32,119070,32]},end_array,end_json]}.
|
||||
{json, "multibyte_utf.json"}.
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
{name, "naked_string"}.
|
||||
{jsx, [{string,<<"this is a naked string">>},end_json]}.
|
||||
{jsx, [{string,"this is a naked string"},end_json]}.
|
||||
{json, "naked_string.json"}.
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
end_array,
|
||||
{integer,0},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{key,"key"},
|
||||
{integer,0},
|
||||
{key,<<"another key">>},
|
||||
{key,"another key"},
|
||||
{integer,0},
|
||||
end_object,
|
||||
{integer,0},
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{name, "noncharacter replaced"}.
|
||||
{jsx, [{string,<<16#fffd/utf8>>},end_json]}.
|
||||
{jsx, [{string,[16#fffd/utf8]},end_json]}.
|
||||
{json, "noncharacter_replaced.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
|
@ -1,4 +1,4 @@
|
|||
{name, "nullbyte replaced"}.
|
||||
{jsx, [{string,<<16#fffd/utf8>>},end_json]}.
|
||||
{jsx, [{string,[16#fffd]},end_json]}.
|
||||
{json, "nullbyte_replaced.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
|
@ -1,22 +1,22 @@
|
|||
{name, "object"}.
|
||||
{jsx, [start_object,
|
||||
{key,<<"foo">>},
|
||||
{string,<<"bar">>},
|
||||
{key,<<"baz">>},
|
||||
{key,"foo"},
|
||||
{string,"bar"},
|
||||
{key,"baz"},
|
||||
{literal,true},
|
||||
{key,<<"false">>},
|
||||
{key,"false"},
|
||||
{literal,null},
|
||||
{key,<<"object">>},
|
||||
{key,"object"},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{string,<<"value">>},
|
||||
{key,"key"},
|
||||
{string,"value"},
|
||||
end_object,
|
||||
{key,<<"list">>},
|
||||
{key,"list"},
|
||||
start_array,
|
||||
{literal,null},
|
||||
{literal,null},
|
||||
{literal,null},
|
||||
start_array,end_array,
|
||||
{string,<<"\n\r\\">>},
|
||||
{string,"\n\r\\"},
|
||||
end_array,end_object,end_json]}.
|
||||
{json, "object.json"}.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{name, "string"}.
|
||||
{jsx, [start_array,
|
||||
{string,<<"this is a random string with \n embedded escapes in it">>},
|
||||
{string,"this is a random string with \n embedded escapes in it"},
|
||||
end_array,end_json]}.
|
||||
{json, "string.json"}.
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
{name, "string_escapes"}.
|
||||
{jsx, [start_array,
|
||||
{string,<<"\"">>},
|
||||
{string,<<"\\">>},
|
||||
{string,<<"/">>},
|
||||
{string,<<"\b">>},
|
||||
{string,<<"\f">>},
|
||||
{string,<<"\n">>},
|
||||
{string,<<"\r">>},
|
||||
{string,<<"\t">>},
|
||||
{string,"\""},
|
||||
{string,"\\"},
|
||||
{string,"/"},
|
||||
{string,"\b"},
|
||||
{string,"\f"},
|
||||
{string,"\n"},
|
||||
{string,"\r"},
|
||||
{string,"\t"},
|
||||
end_array,end_json]}.
|
||||
{json, "string_escapes.json"}.
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{name, "unicode_to_codepoint"}.
|
||||
{jsx, [start_array,
|
||||
{string,<<"arabic letter alef: ">>},
|
||||
{string,<<1575/utf8>>},
|
||||
{string,"arabic letter alef: "},
|
||||
{string,[1575]},
|
||||
end_array,end_json]}.
|
||||
{json, "unicode_to_codepoint.json"}.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{name, "unpaired surrogate replaced"}.
|
||||
{jsx, [start_array,{string,<<16#fffd/utf8, "blah">>},end_array,end_json]}.
|
||||
{jsx, [start_array,{string,16#fffd/utf8 ++ "blah"},end_array,end_json]}.
|
||||
{json, "unpaired_surrogate_replaced.json"}.
|
||||
{jsx_flags, [loose_unicode]}.
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
end_array,
|
||||
{integer,0},
|
||||
start_object,
|
||||
{key,<<"key">>},
|
||||
{key,"key"},
|
||||
{integer,0},
|
||||
{key,<<"another key">>},
|
||||
{key,"another key"},
|
||||
{integer,0},
|
||||
end_object,
|
||||
{integer,0},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue