diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2017-05-25 13:24:35 +0200 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2017-05-25 13:24:35 +0200 |
commit | b56cc927f44b48f54da65ce545549974a1045460 (patch) | |
tree | 8687eb42c348d25fd804244ec97b1f68e1440be5 | |
parent | 4359542333ee8efe3c59e93d59b646176f17a78c (diff) | |
download | elixir-b56cc927f44b48f54da65ce545549974a1045460.tar.gz |
Use :binary.split/2 instead of part+match
-rw-r--r-- | lib/elixir/lib/string.ex | 13 | ||||
-rw-r--r-- | lib/elixir/lib/string_io.ex | 2 |
2 files changed, 5 insertions, 10 deletions
diff --git a/lib/elixir/lib/string.ex b/lib/elixir/lib/string.ex index 2d96ed999..d37daeac0 100644 --- a/lib/elixir/lib/string.ex +++ b/lib/elixir/lib/string.ex @@ -430,15 +430,10 @@ defmodule String do end defp do_splitter(bin, pattern, trim) do - case :binary.match(bin, pattern) do - {0, length} when trim -> - do_splitter(:binary.part(bin, length, byte_size(bin) - length), pattern, trim) - {pos, length} -> - final = pos + length - {:binary.part(bin, 0, pos), - :binary.part(bin, final, byte_size(bin) - final)} - :nomatch -> - {bin, :nomatch} + case :binary.split(bin, pattern) do + ["", second] when trim -> do_splitter(second, pattern, trim) + [first, second] -> {first, second} + [first] -> {first, :nomatch} end end diff --git a/lib/elixir/lib/string_io.ex b/lib/elixir/lib/string_io.ex index 2552494f5..ca4e253d9 100644 --- a/lib/elixir/lib/string_io.ex +++ b/lib/elixir/lib/string_io.ex @@ -266,7 +266,7 @@ defmodule StringIO do {:replace_split, count} -> {result, remainder} = :erlang.split_binary(input, count) - {:erlang.binary_part(result, 0, byte_size(result) - 2) <> "\n", state_after_read(s, remainder, prompt)} + {binary_part(result, 0, byte_size(result) - 2) <> "\n", state_after_read(s, remainder, prompt)} :error -> {{:error, :collect_line}, s} end |