Skip to content

Commit 8e464bf

Browse files
committed
IO data without reverse
1 parent 81d1b29 commit 8e464bf

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

lib/lazy_html.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,7 +500,6 @@ defmodule LazyHTML do
500500
def html_escape(string) when is_binary(string) do
501501
string
502502
|> LazyHTML.Tree.append_escaped([])
503-
|> Enum.reverse()
504503
|> IO.iodata_to_binary()
505504
end
506505

lib/lazy_html/tree.ex

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ defmodule LazyHTML.Tree do
5959

6060
tree
6161
|> to_html(ctx, [])
62-
|> Enum.reverse()
6362
|> IO.iodata_to_binary()
6463
end
6564

@@ -73,17 +72,17 @@ defmodule LazyHTML.Tree do
7372
defp to_html([], _ctx, html), do: html
7473

7574
defp to_html([{tag, attrs, children} | tree], ctx, html) do
76-
html = [tag, ?< | html]
75+
html = [html, ?<, tag]
7776
html = append_attrs(attrs, html)
7877

7978
if tag in @void_tags do
80-
html = ["/>" | html]
79+
html = [html, "/>"]
8180
to_html(tree, ctx, html)
8281
else
83-
html = [?> | html]
82+
html = [html, ?>]
8483
escape_children = tag not in @no_escape_tags
8584
html = to_html(children, %{ctx | escape: escape_children}, html)
86-
html = [?>, tag, "</" | html]
85+
html = [html, "</", tag, ?>]
8786
to_html(tree, ctx, html)
8887
end
8988
end
@@ -94,16 +93,16 @@ defmodule LazyHTML.Tree do
9493
end
9594

9695
defp to_html([{:comment, content} | tree], ctx, html) do
97-
html = ["-->", content, "<!--" | html]
96+
html = [html, "<!--", content, "-->"]
9897
to_html(tree, ctx, html)
9998
end
10099

101100
defp append_attrs([], html), do: html
102101

103102
defp append_attrs([{name, value} | attrs], html) do
104-
html = [~S/="/, name, ?\s | html]
103+
html = [html, ?\s, name, ~S/="/]
105104
html = append_escaped(value, html)
106-
html = [?" | html]
105+
html = [html, ?"]
107106
append_attrs(attrs, html)
108107
end
109108

@@ -117,7 +116,7 @@ defmodule LazyHTML.Tree do
117116

118117
defp append_text(<<_rest::binary>>, text, _whitespace_size, ctx, html)
119118
when not ctx.escape,
120-
do: [text | html]
119+
do: [html, text]
121120

122121
defp append_text(<<rest::binary>>, text, whitespace_size, ctx, html)
123122
when ctx.escape,
@@ -142,12 +141,12 @@ defmodule LazyHTML.Tree do
142141
defp append_escaped(<<>>, text, 0 = _offset, _size, html) do
143142
# We scanned the whole text and there were no characters to escape,
144143
# so we append the whole text.
145-
[text | html]
144+
[html, text]
146145
end
147146

148147
defp append_escaped(<<>>, text, offset, size, html) do
149148
chunk = binary_part(text, offset, size)
150-
[chunk | html]
149+
[html, chunk]
151150
end
152151

153152
escapes = [
@@ -161,7 +160,7 @@ defmodule LazyHTML.Tree do
161160
for {char, escaped} <- escapes do
162161
defp append_escaped(<<unquote(char), rest::binary>>, text, offset, size, html) do
163162
chunk = binary_part(text, offset, size)
164-
html = [unquote(escaped), chunk | html]
163+
html = [html, chunk, unquote(escaped)]
165164
append_escaped(rest, text, offset + size + 1, 0, html)
166165
end
167166
end

0 commit comments

Comments
 (0)