diff --git a/lib/lazy_html.ex b/lib/lazy_html.ex index 358b37e..d814697 100644 --- a/lib/lazy_html.ex +++ b/lib/lazy_html.ex @@ -498,7 +498,7 @@ defmodule LazyHTML do """ @spec html_escape(String.t()) :: String.t() def html_escape(string) when is_binary(string) do - LazyHTML.Tree.append_escaped(string, "") + LazyHTML.Tree.html_escape(string) end # Access diff --git a/lib/lazy_html/tree.ex b/lib/lazy_html/tree.ex index 29edc32..ee30891 100644 --- a/lib/lazy_html/tree.ex +++ b/lib/lazy_html/tree.ex @@ -133,8 +133,12 @@ defmodule LazyHTML.Tree do # # [1]: https://github.com/phoenixframework/phoenix_html/blob/v4.2.1/lib/phoenix_html/engine.ex#L29-L35 - @doc false - def append_escaped(text, html) do + # Note: it is important for this function to be private, so that the + # Erlang compiler can infer that it is safe to use mutating appends + # on the underlying binary and maximise optimisations [1]. + # + # [1]: https://github.com/dashbitco/lazy_html/pull/19 + defp append_escaped(text, html) do append_escaped(text, text, 0, 0, html) end @@ -275,4 +279,7 @@ defmodule LazyHTML.Tree do tree end + + @doc false + def html_escape(string), do: append_escaped(string, "") end