Skip to content

Commit f0fcd64

Browse files
authored
Inline more functions (#13692)
1 parent 8ed692d commit f0fcd64

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

lib/elixir/lib/float.ex

+6-2
Original file line numberDiff line numberDiff line change
@@ -589,14 +589,16 @@ defmodule Float do
589589
590590
For a configurable representation, use `:erlang.float_to_list/2`.
591591
592+
Inlined by the compiler.
593+
592594
## Examples
593595
594596
iex> Float.to_charlist(7.0)
595597
~c"7.0"
596598
597599
"""
598600
@spec to_charlist(float) :: charlist
599-
def to_charlist(float) when is_float(float) do
601+
def to_charlist(float) do
600602
:erlang.float_to_list(float, [:short])
601603
end
602604

@@ -616,14 +618,16 @@ defmodule Float do
616618
617619
For a configurable representation, use `:erlang.float_to_binary/2`.
618620
621+
Inlined by the compiler.
622+
619623
## Examples
620624
621625
iex> Float.to_string(7.0)
622626
"7.0"
623627
624628
"""
625629
@spec to_string(float) :: String.t()
626-
def to_string(float) when is_float(float) do
630+
def to_string(float) do
627631
:erlang.float_to_binary(float, [:short])
628632
end
629633

lib/elixir/lib/map.ex

+3-3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ defmodule Map do
128128
@doc """
129129
Builds a map from the given `keys` and the fixed `value`.
130130
131+
Inlined by the compiler.
132+
131133
## Examples
132134
133135
iex> Map.from_keys([1, 2, 3], :number)
@@ -136,9 +138,7 @@ defmodule Map do
136138
"""
137139
@doc since: "1.14.0"
138140
@spec from_keys([key], value) :: map
139-
def from_keys(keys, value) do
140-
:maps.from_keys(keys, value)
141-
end
141+
defdelegate from_keys(keys, value), to: :maps
142142

143143
@doc """
144144
Returns all keys from `map`.

lib/elixir/src/elixir_rewrite.erl

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
-define(atom, 'Elixir.Atom').
99
-define(bitwise, 'Elixir.Bitwise').
1010
-define(enum, 'Elixir.Enum').
11+
-define(float, 'Elixir.Float').
1112
-define(function, 'Elixir.Function').
1213
-define(integer, 'Elixir.Integer').
1314
-define(io, 'Elixir.IO').
@@ -145,6 +146,7 @@ inline(Mod, Fun, Arity) -> inner_inline(ex_to_erl, Mod, Fun, Arity).
145146
?inline(?list, to_integer, 2, erlang, list_to_integer);
146147
?inline(?list, to_tuple, 1, erlang, list_to_tuple);
147148

149+
?inline(?map, from_keys, 2, maps, from_keys);
148150
?inline(?map, intersect, 2, maps, intersect);
149151
?inline(?map, keys, 1, maps, keys);
150152
?inline(?map, merge, 2, maps, merge);
@@ -239,6 +241,8 @@ rewrite(Receiver, DotMeta, Right, Meta, Args) ->
239241
{EReceiver, ERight, EArgs} = inner_rewrite(ex_to_erl, DotMeta, Receiver, Right, Args),
240242
{{'.', DotMeta, [EReceiver, ERight]}, Meta, EArgs}.
241243

244+
?rewrite(?float, to_charlist, [Arg], erlang, float_to_list, [Arg, [short]]);
245+
?rewrite(?float, to_string, [Arg], erlang, float_to_binary, [Arg, [short]]);
242246
?rewrite(?kernel, is_map_key, [Map, Key], erlang, is_map_key, [Key, Map]);
243247
?rewrite(?map, delete, [Map, Key], maps, remove, [Key, Map]);
244248
?rewrite(?map, fetch, [Map, Key], maps, find, [Key, Map]);

0 commit comments

Comments
 (0)