Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize id matching #519

Merged
merged 3 commits into from
Jan 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/floki/selector.ex
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ 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: %{"id" => id}}, id), do: true

defp id_match?(_node, _id), do: false

defp namespace_match?(_node, namespace) when is_wildcard(namespace), do: true
defp namespace_match?(%HTMLNode{type: :pi}, _type), do: false

Expand Down