File 2934-Eliminate-use-of-sets-size-1-when-sets-is_empty-1-wi.patch of Package erlang
From 6b638b179b79011af87a2b5c4eab7dd0cc6ef2b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org>
Date: Sat, 20 Feb 2021 09:13:04 +0100
Subject: [PATCH 4/6] Eliminate use of sets:size/1 when sets:is_empty/1 will
work
---
lib/compiler/src/beam_ssa_opt.erl | 20 ++++++++++----------
lib/compiler/src/beam_ssa_throw.erl | 6 +++---
lib/compiler/src/v3_kernel.erl | 6 +++---
3 files changed, 16 insertions(+), 16 deletions(-)
diff --git a/lib/compiler/src/beam_ssa_opt.erl b/lib/compiler/src/beam_ssa_opt.erl
index 9d65c6bebc..486d33ef05 100644
--- a/lib/compiler/src/beam_ssa_opt.erl
+++ b/lib/compiler/src/beam_ssa_opt.erl
@@ -96,11 +96,11 @@ fixpoint(_FuncIds, _Order, _Passes, StMap, FuncDb, 0) ->
fixpoint(FuncIds0, Order0, Passes, StMap0, FuncDb0, N) ->
{StMap, FuncDb} = phase(FuncIds0, Passes, StMap0, FuncDb0),
Repeat = changed(FuncIds0, FuncDb0, FuncDb, StMap0, StMap),
- case sets:size(Repeat) of
- 0 ->
+ case sets:is_empty(Repeat) of
+ true ->
%% No change. Fixpoint reached.
{StMap, FuncDb};
- _ ->
+ false ->
%% Repeat the optimizations for functions whose code has
%% changed or for which there is potentially updated type
%% information.
@@ -1436,9 +1436,9 @@ do_reduce_try([{L, Blk} | Bs]=Bs0, Ws0) ->
%% This block is not reachable from the block with the
%% `new_try_tag` instruction. Retain it. There is no
%% need to check it for safety.
- case sets:size(Ws0) of
- 0 -> Bs0;
- _ -> [{L, Blk} | do_reduce_try(Bs, Ws0)]
+ case sets:is_empty(Ws0) of
+ true -> Bs0;
+ false -> [{L, Blk} | do_reduce_try(Bs, Ws0)]
end;
true ->
Ws1 = sets:del_element(L, Ws0),
@@ -1464,7 +1464,7 @@ do_reduce_try([{L, Blk} | Bs]=Bs0, Ws0) ->
end
end;
do_reduce_try([], Ws) ->
- 0 = sets:size(Ws), %Assertion.
+ true = sets:is_empty(Ws), %Assertion.
[].
reduce_try_is([#b_set{op=kill_try_tag}|Is], Acc) ->
@@ -1531,10 +1531,10 @@ trim_try([{L, Blk} | Bs], Unreachable0, Killed, Acc) ->
Unreachable = sets:subtract(Unreachable0, Successors),
trim_try(Bs, Unreachable, Killed, [{L, Blk} | Acc]);
trim_try([], _Unreachable, Killed, Acc0) ->
- case sets:size(Killed) of
- 0 ->
+ case sets:is_empty(Killed) of
+ true ->
Acc0;
- _ ->
+ false ->
%% Remove all `kill_try_tag` instructions referencing removed
%% try/catches.
[{L, Blk#b_blk{is=trim_try_is(Is0, Killed)}} ||
diff --git a/lib/compiler/src/beam_ssa_throw.erl b/lib/compiler/src/beam_ssa_throw.erl
index fc0d53e6ab..cf742ec6ce 100644
--- a/lib/compiler/src/beam_ssa_throw.erl
+++ b/lib/compiler/src/beam_ssa_throw.erl
@@ -106,10 +106,10 @@ scan_1([], Gst) ->
tlh_edges=Edges,
throws=Throws} = Gst,
- case sets:size(Throws) of
- 0 ->
+ case sets:is_empty(Throws) of
+ true ->
no_throws;
- _ ->
+ false ->
TLHs = propagate_tlhs(gb_trees:to_list(Roots), Edges, #{}),
{Throws, TLHs}
end.
diff --git a/lib/compiler/src/v3_kernel.erl b/lib/compiler/src/v3_kernel.erl
index 40cf1c276c..2bb340e26d 100644
--- a/lib/compiler/src/v3_kernel.erl
+++ b/lib/compiler/src/v3_kernel.erl
@@ -1468,10 +1468,10 @@ partition_keys(#ialias{pat=Map}=Alias, Ks) ->
find_key_intersection(Ps) ->
Sets = [sets:from_list(Ks, [{version, 2}]) || Ks <- Ps],
Intersection = sets:intersection(Sets),
- case sets:size(Intersection) of
- 0 ->
+ case sets:is_empty(Intersection) of
+ true ->
none;
- _ ->
+ false ->
All = all(fun (Kset) -> Kset =:= Intersection end, Sets),
case All of
true ->
--
2.26.2