Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions apps/rebar/src/rebar_prv_manifest.erl
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
src_dirs := [file:filename_all()],
extra_src_dirs := [file:filename_all()],
include_dirs := [file:filename_all()],
macros => [macro()],
macros => macros(),
parse_transforms => [any()]}.
-type macro() :: #{key := atom(), value => any()}.
-type macros() :: #{atom() => any()}.
-type manifest() :: #{ apps := [app_context()],
deps := [app_context()],
otp_lib_dir := file:filename_all(),
Expand Down Expand Up @@ -133,7 +133,7 @@ adapt_context(App) ->
src_dirs => [to_binary(D) || D <- SrcDirs],
extra_src_dirs => [to_binary(D) || D <- ExtraSrcDirs],
include_dirs => [to_binary(D) || D <- IncludeDirs],
macros => [to_macro(M) || M <- Macros],
macros => to_macros(Macros),
parse_transforms => ParseTransforms}.

-spec output_manifest(binary(), format(), string() | undefined) -> ok | {error, term()}.
Expand Down Expand Up @@ -169,11 +169,15 @@ format(_Manifest, Format) ->
to_binary(Path) ->
unicode:characters_to_binary(Path).

-spec to_macro(atom() | {atom() | any()}) -> macro().
-spec to_macros(proplists:proplist()) -> macros().
to_macros(Macros) ->
maps:from_list([to_macro(M) || M <- Macros]).
Copy link
Contributor

@vkatsuba vkatsuba Aug 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal, but, since there is already happens a loop over a list it can be make sense to simply it like

to_macros(Macros) ->
   to_macro(Macros, #{}).
   
to_macro([], Acc) ->
    Acc;
to_macro([{Key, Value} | T], Acc) when is_atom(Key) ->
    to_macro(T, Acc#{Key => Value});
to_macro([K | T], Acc) when is_atom(Key) ->
    to_macro(T, Acc#{Key => <<"true">>}).

and get rid of the function call maps:from_list/1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll keep it as is right now since it is fairly readable. We might consider using lists:foldl or a custom recursive functions, but maps:from_list is a NIF so I'd like to see some benchmark first that this really makes a difference for any practical case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, plus a list maybe will not a big it self. As I wrote above - it not a big deal, but by some reason I was think that the one list loop it always a faster then two 🙃 - but as you mention is used a NIF.


-spec to_macro(atom() | {atom(), any()}) -> {atom(), any()}.
to_macro({Key, Value}) when is_atom(Key) ->
#{key => Key, value => Value};
{Key, Value};
to_macro(Key) when is_atom(Key) ->
#{key => Key, value => true}.
{Key, <<"true">>}.

-spec is_json_available() -> boolean().
is_json_available() ->
Expand Down
Loading