Commit 2820d841 authored by rinpatch's avatar rinpatch

Revert "Introduce a lookup table for known tags"

The results are inconsistent run to run, so the optimization probably doesn't
do anything.
parent afd98368
Pipeline #19245 failed with stage
in 1 minute and 13 seconds
defmodule FastSanitize.Fragment do
import Plug.HTML, only: [html_escape_to_iodata: 1]
# Generate a lookup table from atoms to binaries
@known_tags [
for tag <- @known_tags do
string_tag = to_string(tag)
def tag_to_string(unquote(tag)), do: unquote(string_tag)
def tag_to_string("" <> binary), do: binary
def tag_to_string(atom), do: to_string(atom)
def to_tree(bin) do
with {:html, _, [{:head, _, _}, {:body, _, fragment}]} <-
Myhtmlex.decode(bin, format: [:nil_self_closing, :comment_tuple3, :html_atoms]) do
......@@ -149,14 +19,13 @@ defmodule FastSanitize.Fragment do
defp build_start_tag(tag, attrs, nil),
do: ["<", tag_to_string(tag), build_attr_chunks(attrs), "/>"]
defp build_start_tag(tag, attrs, nil), do: ["<", to_string(tag), build_attr_chunks(attrs), "/>"]
defp build_start_tag(tag, attrs, _children) when length(attrs) == 0,
do: ["<", tag_to_string(tag), ">"]
do: ["<", to_string(tag), ">"]
defp build_start_tag(tag, attrs, _children),
do: ["<", tag_to_string(tag), build_attr_chunks(attrs), ">"]
do: ["<", to_string(tag), build_attr_chunks(attrs), ">"]
# empty tuple - fragment was clobbered, return nothing
defp fragment_to_html(nil, _), do: ""
......@@ -180,7 +49,7 @@ defmodule FastSanitize.Fragment do
# every other case, assume a subtree
defp fragment_to_html({tag, attrs, subtree}, scrubber) do
with start_tag <- build_start_tag(tag, attrs, subtree),
end_tag <- ["</", tag_to_string(tag), ">"],
end_tag <- ["</", to_string(tag), ">"],
subtree <- subtree_to_iodata(subtree, scrubber) do
[start_tag, subtree, end_tag]
......@@ -10,6 +10,7 @@ defmodule Mix.Tasks.FastSanitize.Bench do
input =!(Path.join(@input_dir, input_name))
Map.put(acc, input_name, input)
|> IO.inspect()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment