Skip to content

Commit 2c36d8f

Browse files
author
José Valim
committed
Do less work at runtime for %w/%W
1 parent d3238b8 commit 2c36d8f

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

lib/elixir/lib/kernel.ex

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3523,20 +3523,16 @@ defmodule Kernel do
35233523
defp build_cond_clauses([], acc), do: acc
35243524

35253525
defp split_words(string, modifiers) do
3526-
quote do
3527-
mod = case unquote(modifiers) do
3528-
[] -> ?b
3529-
[mod] when mod in [?b, ?a, ?c] -> mod
3530-
_else -> raise ArgumentError, message: "modifier must be one of: b, a, c"
3531-
end
3532-
3533-
parts = String.split(unquote(string))
3526+
mod = case modifiers do
3527+
[] -> ?b
3528+
[mod] when mod in [?b, ?a, ?c] -> mod
3529+
_else -> raise ArgumentError, message: "modifier must be one of: b, a, c"
3530+
end
35343531

3535-
case mod do
3536-
?b -> parts
3537-
?a -> lc p inlist parts, do: binary_to_atom(p)
3538-
?c -> lc p inlist parts, do: binary_to_list(p)
3539-
end
3532+
case mod do
3533+
?b -> quote do: String.split(unquote(string))
3534+
?a -> quote do: lc p inlist String.split(unquote(string)), do: binary_to_atom(p)
3535+
?c -> quote do: lc p inlist String.split(unquote(string)), do: :unicode.characters_to_list(p)
35403536
end
35413537
end
35423538
end

0 commit comments

Comments
 (0)