Skip to content

Commit e0b7f6f

Browse files
committed
Use maps comprehensions and generators in a few places
These are new in OTP 26 so we can simplify a few lines of code using them.
1 parent f29d3a9 commit e0b7f6f

File tree

5 files changed

+8
-8
lines changed

5 files changed

+8
-8
lines changed

src/couch/src/couch_db.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ purge_docs(#db{main_pid = Pid} = Db, UUIDsIdsRevs, Options) ->
420420
% Gather any existing purges with the same UUIDs
421421
UUIDs = element(1, lists:unzip3(UUIDsIdsRevs1)),
422422
Old1 = get_purge_infos(Db, UUIDs),
423-
Old2 = maps:from_list([{UUID, {Id, Revs}} || {_, UUID, Id, Revs} <- Old1]),
423+
Old2 = #{UUID => {Id, Revs} || {_, UUID, Id, Revs} <- Old1},
424424
% Filter out all the purges which have already been processed
425425
FilterCheckFun = fun({UUID, Id, Revs}) ->
426426
case maps:is_key(UUID, Old2) of

src/couch/src/couch_util.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -803,11 +803,11 @@ remove_sensitive_data(KVList) ->
803803
lists:keyreplace(password, 1, KVList1, {password, <<"****">>}).
804804

805805
ejson_to_map(#{} = Val) ->
806-
maps:map(fun(_, V) -> ejson_to_map(V) end, Val);
806+
#{K => ejson_to_map(V) || K := V <- Val};
807807
ejson_to_map(Val) when is_list(Val) ->
808-
lists:map(fun(V) -> ejson_to_map(V) end, Val);
808+
[ejson_to_map(V) || V <- Val];
809809
ejson_to_map({Val}) when is_list(Val) ->
810-
maps:from_list(lists:map(fun({K, V}) -> {K, ejson_to_map(V)} end, Val));
810+
#{K => ejson_to_map(V) || {K, V} <- Val};
811811
ejson_to_map(Val) ->
812812
Val.
813813

src/mem3/src/mem3_reshard_job.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ topoff_impl(#job{source = #shard{} = Source, target = Targets}) ->
411411
BatchSize = config:get_integer(
412412
"rexi", "shard_split_topoff_batch_size", ?INTERNAL_REP_BATCH_SIZE
413413
),
414-
TMap = maps:from_list([{R, T} || #shard{range = R} = T <- Targets]),
414+
TMap = #{R => T || #shard{range = R} = T <- Targets},
415415
Opts = [
416416
{batch_size, BatchSize},
417417
{batch_count, all},

src/nouveau/src/nouveau_bookmark.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ unpack(DbName, PackedBookmark) when is_list(PackedBookmark) ->
5151
unpack(DbName, list_to_binary(PackedBookmark));
5252
unpack(DbName, PackedBookmark) when is_binary(PackedBookmark) ->
5353
Bookmark = jiffy:decode(b64url:decode(PackedBookmark), [return_maps]),
54-
maps:from_list([{range_of(DbName, V), V} || V <- Bookmark]).
54+
#{range_of(DbName, V) => V || V <- Bookmark}.
5555

5656
pack(nil) ->
5757
null;

src/smoosh/src/smoosh_persist.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ persist(true, Waiting, Active, Starting) ->
7171
% already running. We want them to be the first ones to continue after
7272
% restart. We're relying on infinity sorting higher than float and integer
7373
% numeric values here.
74-
AMap = maps:map(fun(_, _) -> infinity end, Active),
75-
SMap = maps:from_list([{K, infinity} || K <- maps:values(Starting)]),
74+
AMap = #{K => infinity || K := _Pid <- Active},
75+
SMap = #{K => infinity || _Ref := K <- Starting},
7676
Path = file_path(Name),
7777
write(maps:merge(WMap, maps:merge(AMap, SMap)), Path).
7878

0 commit comments

Comments
 (0)