Skip to content

Inline more functions #13692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/elixir/lib/float.ex
Original file line number Diff line number Diff line change
Expand Up @@ -589,14 +589,16 @@ defmodule Float do

For a configurable representation, use `:erlang.float_to_list/2`.

Inlined by the compiler.

## Examples

iex> Float.to_charlist(7.0)
~c"7.0"

"""
@spec to_charlist(float) :: charlist
def to_charlist(float) when is_float(float) do
def to_charlist(float) do
:erlang.float_to_list(float, [:short])
end

Expand All @@ -616,14 +618,16 @@ defmodule Float do

For a configurable representation, use `:erlang.float_to_binary/2`.

Inlined by the compiler.

## Examples

iex> Float.to_string(7.0)
"7.0"

"""
@spec to_string(float) :: String.t()
def to_string(float) when is_float(float) do
def to_string(float) do
:erlang.float_to_binary(float, [:short])
end

Expand Down
6 changes: 3 additions & 3 deletions lib/elixir/lib/map.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ defmodule Map do
@doc """
Builds a map from the given `keys` and the fixed `value`.

Inlined by the compiler.

## Examples

iex> Map.from_keys([1, 2, 3], :number)
Expand All @@ -136,9 +138,7 @@ defmodule Map do
"""
@doc since: "1.14.0"
@spec from_keys([key], value) :: map
def from_keys(keys, value) do
:maps.from_keys(keys, value)
end
defdelegate from_keys(keys, value), to: :maps

@doc """
Returns all keys from `map`.
Expand Down
4 changes: 4 additions & 0 deletions lib/elixir/src/elixir_rewrite.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
-define(atom, 'Elixir.Atom').
-define(bitwise, 'Elixir.Bitwise').
-define(enum, 'Elixir.Enum').
-define(float, 'Elixir.Float').
-define(function, 'Elixir.Function').
-define(integer, 'Elixir.Integer').
-define(io, 'Elixir.IO').
Expand Down Expand Up @@ -145,6 +146,7 @@ inline(Mod, Fun, Arity) -> inner_inline(ex_to_erl, Mod, Fun, Arity).
?inline(?list, to_integer, 2, erlang, list_to_integer);
?inline(?list, to_tuple, 1, erlang, list_to_tuple);

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

?rewrite(?float, to_charlist, [Arg], erlang, float_to_list, [Arg, [short]]);
?rewrite(?float, to_string, [Arg], erlang, float_to_binary, [Arg, [short]]);
?rewrite(?kernel, is_map_key, [Map, Key], erlang, is_map_key, [Key, Map]);
?rewrite(?map, delete, [Map, Key], maps, remove, [Key, Map]);
?rewrite(?map, fetch, [Map, Key], maps, find, [Key, Map]);
Expand Down