aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorHenrik Nord <[email protected]>2016-02-25 10:45:10 +0100
committerHenrik Nord <[email protected]>2016-02-25 10:45:10 +0100
commit93c6b942bf99e73e566e3ab8c6dea1848a1e4b1e (patch)
tree00d3c3306e614a1041cb23b66ed362c0fb74428d /lib
parent761804cdda45a71b9e82e5340ca98c3ea94e4886 (diff)
parent38330fa8bfc5e2ea190923fa8f6434b8c5fbedad (diff)
downloadotp-93c6b942bf99e73e566e3ab8c6dea1848a1e4b1e.tar.gz
otp-93c6b942bf99e73e566e3ab8c6dea1848a1e4b1e.tar.bz2
otp-93c6b942bf99e73e566e3ab8c6dea1848a1e4b1e.zip
Merge branch 'benwilson512/better-maps-with' into maint
* benwilson512/better-maps-with: Improved maps:with/2 and maps:without/2 algorithm OTP-13376
Diffstat (limited to 'lib')
-rw-r--r--lib/stdlib/src/maps.erl14
1 files changed, 11 insertions, 3 deletions
diff --git a/lib/stdlib/src/maps.erl b/lib/stdlib/src/maps.erl
index 3c798b7a04..43d10f4800 100644
--- a/lib/stdlib/src/maps.erl
+++ b/lib/stdlib/src/maps.erl
@@ -205,7 +205,7 @@ size(Val) ->
K :: term().
without(Ks,M) when is_list(Ks), is_map(M) ->
- maps:from_list([{K,V}||{K,V} <- maps:to_list(M), not lists:member(K, Ks)]);
+ lists:foldl(fun(K, M1) -> ?MODULE:remove(K, M1) end, M, Ks);
without(Ks,M) ->
erlang:error(error_type(M),[Ks,M]).
@@ -216,8 +216,16 @@ without(Ks,M) ->
Map2 :: map(),
K :: term().
-with(Ks,M) when is_list(Ks), is_map(M) ->
- maps:from_list([{K,V}||{K,V} <- maps:to_list(M), lists:member(K, Ks)]);
+with(Ks,Map1) when is_list(Ks), is_map(Map1) ->
+ Fun = fun(K, List) ->
+ case ?MODULE:find(K, Map1) of
+ {ok, V} ->
+ [{K, V} | List];
+ error ->
+ List
+ end
+ end,
+ ?MODULE:from_list(lists:foldl(Fun, [], Ks));
with(Ks,M) ->
erlang:error(error_type(M),[Ks,M]).