Skip to content

Commit

Permalink
Optimize id matching
Browse files Browse the repository at this point in the history
  • Loading branch information
ypconstante committed Jan 3, 2024
1 parent 69f416c commit f7491c6
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions lib/floki/selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,14 @@ defmodule Floki.Selector do
defp id_match?(%HTMLNode{attributes: []}, _), do: false
defp id_match?(%HTMLNode{type: :pi}, _), do: false

defp id_match?(%HTMLNode{attributes: attributes}, id) do
Enum.any?(attributes, fn attribute ->
case attribute do
{"id", ^id} -> true
_ -> false
end
end)
defp id_match?(%HTMLNode{attributes: attributes}, id) when is_list(attributes) do
id_attr_value = :proplists.get_value("id", attributes, nil)
id_attr_value == id
end

defp id_match?(%HTMLNode{attributes: attributes}, id) when is_map(attributes) do
id_attr_value = attributes["id"]
id_attr_value == id
end

defp namespace_match?(_node, namespace) when is_wildcard(namespace), do: true
Expand Down

0 comments on commit f7491c6

Please sign in to comment.