Skip to content

Optimize Base.decode* #14430

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 1 commit into from
Apr 12, 2025
Merged
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
39 changes: 18 additions & 21 deletions lib/elixir/lib/base.ex
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,12 @@ defmodule Base do
end

defp unquote(decode_name)(char) do
try do
elem({unquote_splicing(decoded)}, char - unquote(min))
rescue
_ -> bad_character!(char)
else
nil -> bad_character!(char)
char -> char
index = char - unquote(min)

cond do
index not in 0..unquote(length(decoded) - 1) -> bad_character!(char)
new_char = elem({unquote_splicing(decoded)}, index) -> new_char
true -> bad_character!(char)
end
end

Expand Down Expand Up @@ -859,13 +858,12 @@ defmodule Base do
end

defp unquote(decode_name)(char) do
try do
elem({unquote_splicing(decoded)}, char - unquote(min))
rescue
_ -> bad_character!(char)
else
nil -> bad_character!(char)
char -> char
index = char - unquote(min)

cond do
index not in 0..unquote(length(decoded) - 1) -> bad_character!(char)
new_char = elem({unquote_splicing(decoded)}, index) -> new_char
true -> bad_character!(char)
end
end

Expand Down Expand Up @@ -1508,13 +1506,12 @@ defmodule Base do
end

defp unquote(decode_name)(char) do
try do
elem({unquote_splicing(decoded)}, char - unquote(min))
rescue
_ -> bad_character!(char)
else
nil -> bad_character!(char)
char -> char
index = char - unquote(min)

cond do
index not in 0..unquote(length(decoded) - 1) -> bad_character!(char)
new_char = elem({unquote_splicing(decoded)}, index) -> new_char
true -> bad_character!(char)
end
end

Expand Down
Loading