Fix for expensive string length check while consuming input. #4

Merged
jimsynz merged 2 commits from fix-big-o into master 2021-01-28 08:49:50 +13:00
Showing only changes of commit 1178ee3ee6 - Show all commits

View file

@ -60,12 +60,9 @@ defmodule LexLuthor.Runner do
line: line,
column: column})
# Are we at the end of the string?
if String.length(string) == len do
{ :ok, Enum.reverse lexer.tokens }
else
{ _ , new_string } = String.split_at string, len
do_lex module, rules, new_string, lexer
case String.split_at(string, len) do
{_, ""} -> {:ok, Enum.reverse(lexer.tokens)}
{_, new_string} -> do_lex(module, rules, new_string, lexer)
end
end
end