Skip to content

Commit 6dbe0c0

Browse files
Fix regression in LazyHTML.Tree.to_html/1 memory usage (#19)
1 parent b1d8f05 commit 6dbe0c0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

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: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ 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, so that the
137+
# Erlang compiler can infer that it is safe to use mutating appends
138+
# on the underlying binary and maximise optimisations [1].
139+
#
140+
# [1]: https://github.com/dashbitco/lazy_html/pull/19
141+
defp append_escaped(text, html) do
138142
append_escaped(text, text, 0, 0, html)
139143
end
140144

@@ -275,4 +279,7 @@ defmodule LazyHTML.Tree do
275279

276280
tree
277281
end
282+
283+
@doc false
284+
def html_escape(string), do: append_escaped(string, "")
278285
end

0 commit comments

Comments
 (0)