From 34c39ec334b8ce40e2730fdcb526c824c49bea57 Mon Sep 17 00:00:00 2001 From: Peter Ullrich Date: Fri, 1 May 2026 16:42:47 +0200 Subject: [PATCH 1/3] Flatten expr list only once, not on every iteration --- lib/eex/lib/eex/compiler.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/eex/lib/eex/compiler.ex b/lib/eex/lib/eex/compiler.ex index 0511023b45..bf57255ce0 100644 --- a/lib/eex/lib/eex/compiler.ex +++ b/lib/eex/lib/eex/compiler.ex @@ -410,7 +410,7 @@ defmodule EEx.Compiler do ) do {wrapped, state} = wrap_expr(current, meta.line, buffer, chars, state) options = [file: state.file, line: line, column: column] ++ state.parser_options - tuples = Code.string_to_quoted!(wrapped, options) + tuples = Code.string_to_quoted!(:lists.flatten(wrapped), options) buffer = insert_quoted(tuples, state.quoted) {buffer, rest} end @@ -426,7 +426,7 @@ defmodule EEx.Compiler do defp generate_buffer([{:eof, _meta}], _buffer, [{content, line, column} | _scope], state) do message = "expected a closing '<% end %>' for block expression in EEx" - expr_meta = non_whitespace_meta(content, line, column, state) + expr_meta = non_whitespace_meta(:lists.flatten(content), line, column, state) syntax_error!(message, expr_meta, state) end @@ -444,8 +444,8 @@ defmodule EEx.Compiler do defp wrap_expr(current, line, buffer, chars, state) do new_lines = List.duplicate(?\n, line - state.line) key = length(state.quoted) - placeholder = ~c"__EEX__(" ++ Integer.to_charlist(key) ++ ~c");" - count = current ++ placeholder ++ new_lines ++ chars + placeholder = [~c"__EEX__(", Integer.to_charlist(key), ~c");"] + count = [current, placeholder, new_lines, chars] new_state = %{state | quoted: [{key, state.engine.handle_end(buffer)} | state.quoted]} {count, new_state} From dde36b4cebdcd1aebe0851563bbea0aa9980333a Mon Sep 17 00:00:00 2001 From: Peter Ullrich Date: Fri, 1 May 2026 17:14:31 +0200 Subject: [PATCH 2/3] Replace quoted keyword list with a map --- lib/eex/lib/eex/compiler.ex | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/eex/lib/eex/compiler.ex b/lib/eex/lib/eex/compiler.ex index bf57255ce0..05aa43e1d7 100644 --- a/lib/eex/lib/eex/compiler.ex +++ b/lib/eex/lib/eex/compiler.ex @@ -303,7 +303,7 @@ defmodule EEx.Compiler do file: file, source: source, line: line, - quoted: [], + quoted: %{}, parser_options: [indentation: indentation] ++ parser_options, indentation: indentation } @@ -366,7 +366,7 @@ defmodule EEx.Compiler do rest, state.engine.handle_begin(buffer), [{contents, start_line, start_column} | scope], - %{state | quoted: [], line: line} + %{state | quoted: %{}, line: line} ) if mark == ~c"" and not match?({:=, _, [_, _]}, contents) do @@ -443,10 +443,10 @@ defmodule EEx.Compiler do defp wrap_expr(current, line, buffer, chars, state) do new_lines = List.duplicate(?\n, line - state.line) - key = length(state.quoted) + key = map_size(state.quoted) placeholder = [~c"__EEX__(", Integer.to_charlist(key), ~c");"] count = [current, placeholder, new_lines, chars] - new_state = %{state | quoted: [{key, state.engine.handle_end(buffer)} | state.quoted]} + new_state = %{state | quoted: Map.put(state.quoted, key, state.engine.handle_end(buffer))} {count, new_state} end @@ -479,8 +479,7 @@ defmodule EEx.Compiler do # Changes placeholder to real expression defp insert_quoted({:__EEX__, _, [key]}, quoted) do - {^key, value} = List.keyfind(quoted, key, 0) - value + Map.get(quoted, key) end defp insert_quoted({left, line, right}, quoted) do From 88687669f90e06f36bf2c3a74daa8e2831d74325 Mon Sep 17 00:00:00 2001 From: Peter Ullrich Date: Fri, 1 May 2026 17:18:36 +0200 Subject: [PATCH 3/3] Replace Map.get with Map.fetch! MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/eex/lib/eex/compiler.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/eex/lib/eex/compiler.ex b/lib/eex/lib/eex/compiler.ex index 05aa43e1d7..4d441c0e9b 100644 --- a/lib/eex/lib/eex/compiler.ex +++ b/lib/eex/lib/eex/compiler.ex @@ -479,7 +479,7 @@ defmodule EEx.Compiler do # Changes placeholder to real expression defp insert_quoted({:__EEX__, _, [key]}, quoted) do - Map.get(quoted, key) + Map.fetch!(quoted, key) end defp insert_quoted({left, line, right}, quoted) do