From 50bf953127678ef7b921243c6994311a6274ecfa Mon Sep 17 00:00:00 2001 From: preciz Date: Fri, 4 Sep 2026 20:36:14 +0200 Subject: [PATCH] Transition json_escape/5 to 4-arity after escaping After finalizing a chunk, transition back to json_escape/4 instead of passing 0 to json_escape/5. This avoids redundant binary_part/3 calls on consecutive escape characters and reduces VM register overhead. This aligns json_escape with html_escape and improves performance. --- lib/phoenix_html.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/phoenix_html.ex b/lib/phoenix_html.ex index a3dfcc6..b469d63 100644 --- a/lib/phoenix_html.ex +++ b/lib/phoenix_html.ex @@ -415,7 +415,7 @@ defmodule Phoenix.HTML do for {match, insert} <- escapes do defp json_escape(<>, skip, original, acc, len) do part = binary_part(original, skip, len) - json_escape(rest, skip + len + 1, original, [acc, part | unquote(insert)], 0) + json_escape(rest, skip + len + 1, original, [acc, part | unquote(insert)]) end end