summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Uhlig <juhlig@hnc-agency.org>2023-05-03 10:39:31 +0200
committerJan Uhlig <juhlig@hnc-agency.org>2023-05-03 10:39:31 +0200
commit83744bb43d741c32066fe81a6cc7a4a397717f63 (patch)
tree27e1b0552079f75a4f71513008df85f50fe758aa
parent465720cf8b6f3c14ebca43c3ce852d135b86bdbe (diff)
downloaderlang-83744bb43d741c32066fe81a6cc7a4a397717f63.tar.gz
Use map generator in sets:filter/2 for version 2 sets
-rw-r--r--lib/stdlib/src/sets.erl17
1 files changed, 3 insertions, 14 deletions
diff --git a/lib/stdlib/src/sets.erl b/lib/stdlib/src/sets.erl
index 816fb85a48..dccc6dcf3a 100644
--- a/lib/stdlib/src/sets.erl
+++ b/lib/stdlib/src/sets.erl
@@ -466,23 +466,12 @@ fold_1(Fun, Acc, Iter) ->
Set1 :: set(Element),
Set2 :: set(Element).
filter(F, #{}=D) when is_function(F, 1)->
- maps:from_keys(filter_1(F, maps:iterator(D)), ?VALUE);
+ %% For this purpose, it is more efficient to use
+ %% maps:from_keys than a map comprehension.
+ maps:from_keys([K || K := _ <- D, F(K)], ?VALUE);
filter(F, #set{}=D) when is_function(F, 1)->
filter_set(F, D).
-filter_1(Fun, Iter) ->
- case maps:next(Iter) of
- {K, _, NextIter} ->
- case Fun(K) of
- true ->
- [K | filter_1(Fun, NextIter)];
- false ->
- filter_1(Fun, NextIter)
- end;
- none ->
- []
- end.
-
%% get_slot(Hashdb, Key) -> Slot.
%% Get the slot. First hash on the new range, if we hit a bucket
%% which has not been split use the unsplit buddy bucket.