minor refactoring of feature detection

This commit is contained in:
alisdair sullivan 2014-04-21 23:44:41 +00:00
parent 4f63503aa2
commit 649329c362
2 changed files with 4 additions and 4 deletions

View file

@ -1,7 +1,7 @@
case os:getenv("JSX_NOMAPS") or proplists:get_value(jsx_nomaps, CONFIG, false) of case os:getenv("JSX_NOMAPS") or proplists:get_value(jsx_nomaps, CONFIG, false) of
false -> false ->
try file:script("config/maps") of try file:script("config/maps") of
{ok, true} -> [{erl_opts, [{d, release_supports_maps}]}] ++ CONFIG; {ok, true} -> [{erl_opts, [{d, maps_support}]}] ++ CONFIG;
_ -> CONFIG _ -> CONFIG
catch _:_ -> CONFIG catch _:_ -> CONFIG
end; end;

View file

@ -39,11 +39,11 @@ encode(Term) -> encode(Term, ?MODULE).
-spec encode(Term::any(), EntryPoint::module()) -> any(). -spec encode(Term::any(), EntryPoint::module()) -> any().
-ifndef(release_supports_maps). -ifndef(maps_support).
encode(Term, EntryPoint) -> encode_(Term, EntryPoint). encode(Term, EntryPoint) -> encode_(Term, EntryPoint).
-endif. -endif.
-ifdef(release_supports_maps). -ifdef(maps_support).
encode(Map, _EntryPoint) when is_map(Map), map_size(Map) < 1 -> [start_object, end_object]; encode(Map, _EntryPoint) when is_map(Map), map_size(Map) < 1 -> [start_object, end_object];
encode(Term, EntryPoint) when is_map(Term) -> encode(Term, EntryPoint) when is_map(Term) ->
lists:flatten( lists:flatten(
@ -72,7 +72,7 @@ unzip(List) -> unzip(List, []).
unzip([], Acc) -> lists:reverse(Acc); unzip([], Acc) -> lists:reverse(Acc);
unzip([{K, V}|Rest], Acc) when is_binary(K); is_atom(K); is_integer(K) -> unzip(Rest, [V, K] ++ Acc). unzip([{K, V}|Rest], Acc) when is_binary(K); is_atom(K); is_integer(K) -> unzip(Rest, [V, K] ++ Acc).
-ifdef(release_supports_maps). -ifdef(maps_support).
unpack(Map) -> unpack(maps:keys(Map), Map, []). unpack(Map) -> unpack(maps:keys(Map), Map, []).
unpack([], _, Acc) -> lists:reverse(Acc); unpack([], _, Acc) -> lists:reverse(Acc);