mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 18:57:45 +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
|
@ -104,7 +104,7 @@ void FormAssociatedElement::reset_form_owner()
|
|||
// 1. If the first element in element's tree, in tree order, to have an ID that is identical to element's form content attribute's value, is a form element, then associate the element with that form element.
|
||||
auto form_value = html_element.attribute(HTML::AttributeNames::form);
|
||||
html_element.root().for_each_in_inclusive_subtree_of_type<HTMLFormElement>([this, &form_value](HTMLFormElement& form_element) {
|
||||
if (form_element.attribute(HTML::AttributeNames::id) == form_value) {
|
||||
if (form_element.id() == form_value) {
|
||||
set_form(&form_element);
|
||||
return IterationDecision::Break;
|
||||
}
|
||||
|
|
|
@ -902,8 +902,8 @@ Vector<FlyString> HTMLFormElement::supported_property_names() const
|
|||
|
||||
// 2. If candidate has a name attribute, add an entry to sourced names with that name attribute's value as the
|
||||
// string, candidate as the element, and name as the source.
|
||||
if (auto maybe_name = candidate->attribute(HTML::AttributeNames::name); maybe_name.has_value())
|
||||
sourced_names.append(SourcedName { maybe_name.value(), candidate, SourcedName::Source::Name, {} });
|
||||
if (candidate->name().has_value())
|
||||
sourced_names.append(SourcedName { candidate->name().value(), candidate, SourcedName::Source::Name, {} });
|
||||
}
|
||||
|
||||
// 3. For each img element candidate whose form owner is the form element:
|
||||
|
@ -920,8 +920,8 @@ Vector<FlyString> HTMLFormElement::supported_property_names() const
|
|||
|
||||
// 2. If candidate has a name attribute, add an entry to sourced names with that name attribute's value as the
|
||||
// string, candidate as the element, and name as the source.
|
||||
if (auto maybe_name = candidate->attribute(HTML::AttributeNames::name); maybe_name.has_value())
|
||||
sourced_names.append(SourcedName { maybe_name.value(), candidate, SourcedName::Source::Name, {} });
|
||||
if (candidate->name().has_value())
|
||||
sourced_names.append(SourcedName { candidate->name().value(), candidate, SourcedName::Source::Name, {} });
|
||||
}
|
||||
|
||||
// 4. For each entry past entry in the past names map add an entry to sourced names with the past entry's name as
|
||||
|
@ -984,8 +984,7 @@ WebIDL::ExceptionOr<JS::Value> HTMLFormElement::named_item_value(FlyString const
|
|||
if (!is_form_control(element, *this))
|
||||
return false;
|
||||
|
||||
// FIXME: DOM::Element::name() isn't cached
|
||||
return name == element.id() || name == element.attribute(HTML::AttributeNames::name);
|
||||
return name == element.id() || name == element.name();
|
||||
});
|
||||
|
||||
// 2. If candidates is empty, let candidates be a live RadioNodeList object containing all the img elements,
|
||||
|
@ -1000,8 +999,7 @@ WebIDL::ExceptionOr<JS::Value> HTMLFormElement::named_item_value(FlyString const
|
|||
if (element.form() != this)
|
||||
return false;
|
||||
|
||||
// FIXME: DOM::Element::name() isn't cached
|
||||
return name == element.id() || name == element.attribute(HTML::AttributeNames::name);
|
||||
return name == element.id() || name == element.name();
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -54,9 +54,8 @@ void HTMLMetaElement::inserted()
|
|||
// * The element is in a document tree
|
||||
// * The element has a name attribute, whose value is an ASCII case-insensitive match for theme-color
|
||||
// * The element has a content attribute
|
||||
auto name = attribute(AttributeNames::name);
|
||||
auto content = attribute(AttributeNames::content);
|
||||
if (name.has_value() && name->bytes_as_string_view().equals_ignoring_ascii_case("theme-color"sv) && content.has_value()) {
|
||||
if (name().has_value() && name()->equals_ignoring_ascii_case("theme-color"sv) && content.has_value()) {
|
||||
auto context = CSS::Parser::ParsingContext { document() };
|
||||
|
||||
// 2. For each element in candidate elements:
|
||||
|
|
|
@ -76,8 +76,8 @@ WebIDL::ExceptionOr<void> NavigableContainer::create_new_child_navigable()
|
|||
Optional<String> target_name;
|
||||
|
||||
// 5. If element has a name content attribute, then set targetName to the value of that attribute.
|
||||
if (auto value = attribute(HTML::AttributeNames::name); value.has_value())
|
||||
target_name = move(value);
|
||||
if (name().has_value())
|
||||
target_name = name().value().to_string();
|
||||
|
||||
// 6. Let documentState be a new document state, with
|
||||
// - document: document
|
||||
|
|
|
@ -1587,8 +1587,8 @@ Vector<FlyString> Window::supported_property_names() const
|
|||
// and are in a document tree with window's associated Document as their root.
|
||||
associated_document().for_each_in_subtree_of_type<DOM::Element>([&property_names](auto& element) -> IterationDecision {
|
||||
if (is<HTMLEmbedElement>(element) || is<HTMLFormElement>(element) || is<HTMLImageElement>(element) || is<HTMLObjectElement>(element)) {
|
||||
if (auto const& name = element.attribute(AttributeNames::name); name.has_value())
|
||||
property_names.set(name.value(), AK::HashSetExistingEntryBehavior::Keep);
|
||||
if (element.name().has_value())
|
||||
property_names.set(element.name().value(), AK::HashSetExistingEntryBehavior::Keep);
|
||||
}
|
||||
if (auto const& name = element.id(); name.has_value())
|
||||
property_names.set(name.value().to_string(), AK::HashSetExistingEntryBehavior::Keep);
|
||||
|
@ -1636,9 +1636,9 @@ WebIDL::ExceptionOr<JS::Value> Window::named_item_value(FlyString const& name) c
|
|||
// whose filter matches only named objects of window with the name name. (By definition, these will all be elements.)
|
||||
return DOM::HTMLCollection::create(mutable_this.associated_document(), DOM::HTMLCollection::Scope::Descendants, [name](auto& element) -> bool {
|
||||
if ((is<HTMLEmbedElement>(element) || is<HTMLFormElement>(element) || is<HTMLImageElement>(element) || is<HTMLObjectElement>(element))
|
||||
&& (element.attribute(AttributeNames::name) == name))
|
||||
&& (element.name() == name))
|
||||
return true;
|
||||
return element.attribute(AttributeNames::id) == name;
|
||||
return element.id() == name;
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -1664,9 +1664,9 @@ Window::NamedObjects Window::named_objects(StringView name)
|
|||
// HTML elements that have an id content attribute whose value is name and are in a document tree with window's associated Document as their root.
|
||||
associated_document().for_each_in_subtree_of_type<DOM::Element>([&objects, &name](auto& element) -> IterationDecision {
|
||||
if ((is<HTMLEmbedElement>(element) || is<HTMLFormElement>(element) || is<HTMLImageElement>(element) || is<HTMLObjectElement>(element))
|
||||
&& (element.attribute(AttributeNames::name) == name))
|
||||
&& (element.name() == name))
|
||||
objects.elements.append(element);
|
||||
else if (element.attribute(AttributeNames::id) == name)
|
||||
else if (element.id() == name)
|
||||
objects.elements.append(element);
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue