From 0baf25d2c4a44f67b8a143177d1bad541d774661 Mon Sep 17 00:00:00 2001 From: Peter Ullrich Date: Sat, 2 May 2026 14:36:46 +0200 Subject: [PATCH 1/2] Inline `decode_name/1 in all three compile-time blocks Unroll validate16XXX for 8/4/2 bytes Fast-path remove_ignored/2 --- lib/elixir/lib/base.ex | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/elixir/lib/base.ex b/lib/elixir/lib/base.ex index d2e3da7ca77..a59f3506bac 100644 --- a/lib/elixir/lib/base.ex +++ b/lib/elixir/lib/base.ex @@ -152,7 +152,10 @@ defmodule Base do defp remove_ignored(string, nil), do: string defp remove_ignored(string, :whitespace) do - for <>, char not in ~c"\s\t\r\n", into: <<>>, do: <> + case :binary.match(string, [<>, <>, <>, <>]) do + :nomatch -> string + _ -> for <>, char not in ~c"\s\t\r\n", into: <<>>, do: <> + end end @doc """ @@ -376,6 +379,26 @@ defmodule Base do defp unquote(validate_name)(<<>>), do: true + defp unquote(validate_name)(<>) do + unquote(valid_char_name)(c1) and + unquote(valid_char_name)(c2) and + unquote(valid_char_name)(c3) and + unquote(valid_char_name)(c4) and + unquote(valid_char_name)(c5) and + unquote(valid_char_name)(c6) and + unquote(valid_char_name)(c7) and + unquote(valid_char_name)(c8) and + unquote(validate_name)(rest) + end + + defp unquote(validate_name)(<>) do + unquote(valid_char_name)(c1) and + unquote(valid_char_name)(c2) and + unquote(valid_char_name)(c3) and + unquote(valid_char_name)(c4) and + unquote(validate_name)(rest) + end + defp unquote(validate_name)(<>) do unquote(valid_char_name)(c1) and unquote(valid_char_name)(c2) and @@ -391,6 +414,7 @@ defmodule Base do defp unquote(valid_char_name)(_char), do: false + @compile {:inline, [{decode_name, 1}]} defp unquote(decode_name)(char) do index = char - unquote(min) @@ -870,6 +894,7 @@ defmodule Base do defp unquote(valid_char_name)(_char), do: false + @compile {:inline, [{decode_name, 1}]} defp unquote(decode_name)(char) do index = char - unquote(min) @@ -1526,6 +1551,7 @@ defmodule Base do defp unquote(valid_char_name)(_char), do: false + @compile {:inline, [{decode_name, 1}]} defp unquote(decode_name)(char) do index = char - unquote(min) From 67fbe99c1616b01496b05a1d2981887ed0ff7116 Mon Sep 17 00:00:00 2001 From: Peter Ullrich Date: Sat, 2 May 2026 18:48:10 +0200 Subject: [PATCH 2/2] Revert decode_name and remove_ignored changes --- lib/elixir/lib/base.ex | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/elixir/lib/base.ex b/lib/elixir/lib/base.ex index a59f3506bac..ef739ad029c 100644 --- a/lib/elixir/lib/base.ex +++ b/lib/elixir/lib/base.ex @@ -152,10 +152,7 @@ defmodule Base do defp remove_ignored(string, nil), do: string defp remove_ignored(string, :whitespace) do - case :binary.match(string, [<>, <>, <>, <>]) do - :nomatch -> string - _ -> for <>, char not in ~c"\s\t\r\n", into: <<>>, do: <> - end + for <>, char not in ~c"\s\t\r\n", into: <<>>, do: <> end @doc """ @@ -414,7 +411,6 @@ defmodule Base do defp unquote(valid_char_name)(_char), do: false - @compile {:inline, [{decode_name, 1}]} defp unquote(decode_name)(char) do index = char - unquote(min) @@ -894,7 +890,6 @@ defmodule Base do defp unquote(valid_char_name)(_char), do: false - @compile {:inline, [{decode_name, 1}]} defp unquote(decode_name)(char) do index = char - unquote(min) @@ -1551,7 +1546,6 @@ defmodule Base do defp unquote(valid_char_name)(_char), do: false - @compile {:inline, [{decode_name, 1}]} defp unquote(decode_name)(char) do index = char - unquote(min)