mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
LibWeb: Cache lowercased tag name for getElementsByTagName() iteration
Instead of calling to_lowercase() on two strings for every step while iterating over the HTMLCollection returned by getElementsByTagName(), we now cache the lowercased tag name beforehand and reuse it. 2.4x speed-up on WebKit/PerformanceTests/DOM/DOMDivWalk.html
This commit is contained in:
parent
ec340f03a5
commit
76580bb9ba
5 changed files with 8 additions and 7 deletions
|
@ -133,10 +133,11 @@ JS::NonnullGCPtr<HTMLCollection> ParentNode::get_elements_by_tag_name(Deprecated
|
|||
|
||||
// 2. Otherwise, if root’s node document is an HTML document, return a HTMLCollection rooted at root, whose filter matches the following descendant elements:
|
||||
if (root().document().document_type() == Document::Type::HTML) {
|
||||
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name](Element const& element) {
|
||||
auto qualified_name_in_ascii_lowercase = qualified_name.to_lowercase();
|
||||
return HTMLCollection::create(*this, HTMLCollection::Scope::Descendants, [qualified_name, qualified_name_in_ascii_lowercase](Element const& element) {
|
||||
// - Whose namespace is the HTML namespace and whose qualified name is qualifiedName, in ASCII lowercase.
|
||||
if (element.namespace_() == Namespace::HTML)
|
||||
return element.qualified_name().to_lowercase() == qualified_name.to_lowercase();
|
||||
return element.qualified_name() == qualified_name_in_ascii_lowercase;
|
||||
|
||||
// - Whose namespace is not the HTML namespace and whose qualified name is qualifiedName.
|
||||
return element.qualified_name() == qualified_name;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue