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 1 commit
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
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
ypconstante marked this conversation as resolved.
Show resolved Hide resolved
id_attr_value = attributes["id"]
id_attr_value == id
end

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