Closed Kabie closed 5 years ago
Thanks for the link. My first go used pattern matching but as it turns out, compiling 39,000+ functions takes a really long time (3-4 minutes).
for {codepoint, replacement} <- @replacements do
defp transliterate([unquote(codepoint) | rest], acc, ignored_codepoints) do
if unquote(codepoint) in ignored_codepoints do
transliterate(rest, [<<unquote(codepoint)::utf8>> | acc], ignored_codepoints)
else
transliterate(rest, [unquote(replacement) | acc], ignored_codepoints)
end
end
end
I went with a touch longer execution time (less than 1 µs more, apparently).
Five Elixir releases later and compilation still takes a minute and a half on my machine.
Closing because the slightly faster runtime performance will probably never outweigh much slower builds.
I believe this is a perfect usecase for pattern matching lookup:
https://github.com/devonestes/fast-elixir#map-lookup-vs-pattern-matching-lookup-code