mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 01:27:34 +00:00
LibWeb: Use cached element name and id where possible
Instead of looking up in the named node map, we can simply use the cached name and ID on the element.
This commit is contained in:
parent
41f84deb9f
commit
0695236408
11 changed files with 30 additions and 36 deletions
|
@ -1285,7 +1285,7 @@ JS::NonnullGCPtr<HTMLCollection> Document::anchors()
|
|||
{
|
||||
if (!m_anchors) {
|
||||
m_anchors = HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [](Element const& element) {
|
||||
return is<HTML::HTMLAnchorElement>(element) && element.has_attribute(HTML::AttributeNames::name);
|
||||
return is<HTML::HTMLAnchorElement>(element) && element.name().has_value();
|
||||
});
|
||||
}
|
||||
return *m_anchors;
|
||||
|
@ -1828,7 +1828,7 @@ Element* Document::find_a_potential_indicated_element(FlyString const& fragment)
|
|||
// whose value is equal to fragment, then return the first such element in tree order.
|
||||
Element* element_with_name = nullptr;
|
||||
root().for_each_in_subtree_of_type<Element>([&](Element const& element) {
|
||||
if (element.attribute(HTML::AttributeNames::name) == fragment) {
|
||||
if (element.name() == fragment) {
|
||||
element_with_name = const_cast<Element*>(&element);
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
|
|
|
@ -118,12 +118,10 @@ Vector<FlyString> HTMLCollection::supported_property_names() const
|
|||
}
|
||||
|
||||
// 2. If element is in the HTML namespace and has a name attribute whose value is neither the empty string nor is in result, append element’s name attribute value to result.
|
||||
if (element->namespace_uri() == Namespace::HTML) {
|
||||
if (auto maybe_name = element->attribute(HTML::AttributeNames::name); maybe_name.has_value()) {
|
||||
auto name = maybe_name.release_value();
|
||||
if (!name.is_empty() && !result.contains_slow(name))
|
||||
result.append(name);
|
||||
}
|
||||
if (element->namespace_uri() == Namespace::HTML && element->name().has_value()) {
|
||||
auto name = element->name().value();
|
||||
if (!name.is_empty() && !result.contains_slow(name))
|
||||
result.append(move(name));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1481,8 +1481,8 @@ String Node::debug_description() const
|
|||
builder.append(node_name().to_deprecated_fly_string().to_lowercase());
|
||||
if (is_element()) {
|
||||
auto const& element = static_cast<DOM::Element const&>(*this);
|
||||
if (auto id = element.get_attribute(HTML::AttributeNames::id); id.has_value())
|
||||
builder.appendff("#{}", id.value());
|
||||
if (element.id().has_value())
|
||||
builder.appendff("#{}", element.id().value());
|
||||
for (auto const& class_name : element.class_names())
|
||||
builder.appendff(".{}", class_name);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue