Skip to content

Commit 960a568

Browse files
committed
Optimize and streamline more code in descr
1 parent f6d8eb4 commit 960a568

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

lib/elixir/lib/module/types/descr.ex

+25-29
Original file line numberDiff line numberDiff line change
@@ -915,14 +915,9 @@ defmodule Module.Types.Descr do
915915
true
916916

917917
# The key is not shared between positive and negative maps,
918-
# and because the negative type is required, there is no value in common
919-
tag == :closed and not is_optional_static(neg_type) ->
920-
false
921-
922-
# The key is not shared between positive and negative maps,
923-
# but because the negative type is not required, there may be a value in common
918+
# if the negative type is optional, then there may be a value in common
924919
tag == :closed ->
925-
true
920+
is_optional_static(neg_type)
926921

927922
# There may be value in common
928923
tag == :open ->
@@ -937,12 +932,17 @@ defmodule Module.Types.Descr do
937932
empty?(diff) or map_empty?(tag, Map.put(fields, key, diff), negs)
938933

939934
%{} ->
940-
if neg_tag == :closed and not is_optional_static(type) do
941-
false
942-
else
943-
# an absent key in a open negative map can be ignored
944-
diff = difference(type, tag_to_type(neg_tag))
945-
empty?(diff) or map_empty?(tag, Map.put(fields, key, diff), negs)
935+
cond do
936+
neg_tag == :open ->
937+
true
938+
939+
neg_tag == :closed and not is_optional_static(type) ->
940+
false
941+
942+
true ->
943+
# an absent key in a open negative map can be ignored
944+
diff = difference(type, tag_to_type(neg_tag))
945+
empty?(diff) or map_empty?(tag, Map.put(fields, key, diff), negs)
946946
end
947947
end
948948
end)) or map_empty?(tag, fields, negs)
@@ -1412,24 +1412,20 @@ defmodule Module.Types.Descr do
14121412
# are disjoint on their first component.
14131413
defp pair_eliminate_negations(negative, t, s) do
14141414
{pair_union, diff_of_t_i} =
1415-
Enum.reduce(
1416-
negative,
1417-
{[], t},
1418-
fn {t_i, s_i}, {accu, diff_of_t_i} ->
1419-
i = intersection(t, t_i)
1420-
1421-
if empty?(i) do
1422-
{accu, diff_of_t_i}
1423-
else
1424-
diff_of_t_i = difference(diff_of_t_i, t_i)
1425-
s_diff = difference(s, s_i)
1415+
Enum.reduce(negative, {[], t}, fn {t_i, s_i}, {accu, diff_of_t_i} ->
1416+
i = intersection(t, t_i)
14261417

1427-
if empty?(s_diff),
1428-
do: {accu, diff_of_t_i},
1429-
else: {[i | accu], diff_of_t_i}
1430-
end
1418+
if empty?(i) do
1419+
{accu, diff_of_t_i}
1420+
else
1421+
diff_of_t_i = difference(diff_of_t_i, t_i)
1422+
s_diff = difference(s, s_i)
1423+
1424+
if empty?(s_diff),
1425+
do: {accu, diff_of_t_i},
1426+
else: {[i | accu], diff_of_t_i}
14311427
end
1432-
)
1428+
end)
14331429

14341430
[diff_of_t_i | pair_union]
14351431
end

0 commit comments

Comments
 (0)