Skip to content

Commit dc388a7

Browse files
committed
Fix regression in LazyHTML.Tree.to_html/1 memory usage
1 parent b1d8f05 commit dc388a7

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

lib/lazy_html.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ defmodule LazyHTML do
498498
"""
499499
@spec html_escape(String.t()) :: String.t()
500500
def html_escape(string) when is_binary(string) do
501-
LazyHTML.Tree.append_escaped(string, "")
501+
LazyHTML.Tree.html_escape(string)
502502
end
503503

504504
# Access

lib/lazy_html/tree.ex

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ defmodule LazyHTML.Tree do
133133
#
134134
# [1]: https://github.com/phoenixframework/phoenix_html/blob/v4.2.1/lib/phoenix_html/engine.ex#L29-L35
135135

136-
@doc false
137-
def append_escaped(text, html) do
136+
# Note: it is important for this function to be private to maximise
137+
# optimisation, see https://github.com/dashbitco/lazy_html/pull/18#issuecomment-3162730539.
138+
defp append_escaped(text, html) do
138139
append_escaped(text, text, 0, 0, html)
139140
end
140141

@@ -275,4 +276,7 @@ defmodule LazyHTML.Tree do
275276

276277
tree
277278
end
279+
280+
@doc false
281+
def html_escape(string), do: append_escaped(string, "")
278282
end

0 commit comments

Comments
 (0)