summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2020-05-30 13:06:26 +0200
committerAndreas Kling <kling@serenityos.org>2020-05-30 13:06:26 +0200
commit7f22e2a3c47e53ffa31f864a99481865cfbd6867 (patch)
tree3fddee8126d663f72a2abed36650cdac512c9dc9
parent770372ad029f211dbd0d7e9f3d4ffd59737b8660 (diff)
downloadserenity-7f22e2a3c47e53ffa31f864a99481865cfbd6867.zip
LibWeb: Use the globals from HTML::AttributeNames in style resolution
Using these avoids the FlyString lookups, so we should basically always prefer them over string literal attribute names.
-rw-r--r--Libraries/LibWeb/CSS/StyleResolver.cpp2
-rw-r--r--Libraries/LibWeb/DOM/AttributeNames.cpp4
-rw-r--r--Libraries/LibWeb/DOM/AttributeNames.h2
-rw-r--r--Libraries/LibWeb/DOM/Node.cpp4
4 files changed, 9 insertions, 3 deletions
diff --git a/Libraries/LibWeb/CSS/StyleResolver.cpp b/Libraries/LibWeb/CSS/StyleResolver.cpp
index 4ad6d818af..6a0f14b88d 100644
--- a/Libraries/LibWeb/CSS/StyleResolver.cpp
+++ b/Libraries/LibWeb/CSS/StyleResolver.cpp
@@ -391,7 +391,7 @@ NonnullRefPtr<StyleProperties> StyleResolver::resolve_style(const Element& eleme
}
}
- auto style_attribute = element.attribute("style");
+ auto style_attribute = element.attribute(HTML::AttributeNames::style);
if (!style_attribute.is_null()) {
if (auto declaration = parse_css_declaration(style_attribute)) {
for (auto& property : declaration->properties()) {
diff --git a/Libraries/LibWeb/DOM/AttributeNames.cpp b/Libraries/LibWeb/DOM/AttributeNames.cpp
index c4c5b2b135..eda5c3f7e1 100644
--- a/Libraries/LibWeb/DOM/AttributeNames.cpp
+++ b/Libraries/LibWeb/DOM/AttributeNames.cpp
@@ -33,6 +33,8 @@ namespace AttributeNames {
FlyString id;
FlyString class_;
FlyString type;
+FlyString href;
+FlyString style;
void initialize()
{
@@ -42,6 +44,8 @@ void initialize()
id = "id";
class_ = "class";
type = "type";
+ href = "href";
+ style = "style";
s_initialized = true;
}
diff --git a/Libraries/LibWeb/DOM/AttributeNames.h b/Libraries/LibWeb/DOM/AttributeNames.h
index 32e3600a75..5c4393ad09 100644
--- a/Libraries/LibWeb/DOM/AttributeNames.h
+++ b/Libraries/LibWeb/DOM/AttributeNames.h
@@ -37,6 +37,8 @@ void initialize();
extern FlyString id;
extern FlyString class_;
extern FlyString type;
+extern FlyString href;
+extern FlyString style;
}
}
diff --git a/Libraries/LibWeb/DOM/Node.cpp b/Libraries/LibWeb/DOM/Node.cpp
index 778a1cf00c..8d8f5bd2d9 100644
--- a/Libraries/LibWeb/DOM/Node.cpp
+++ b/Libraries/LibWeb/DOM/Node.cpp
@@ -63,7 +63,7 @@ Node::~Node()
const HTMLAnchorElement* Node::enclosing_link_element() const
{
for (auto* node = this; node; node = node->parent()) {
- if (is<HTMLAnchorElement>(*node) && to<HTMLAnchorElement>(*node).has_attribute("href"))
+ if (is<HTMLAnchorElement>(*node) && to<HTMLAnchorElement>(*node).has_attribute(HTML::AttributeNames::href))
return to<HTMLAnchorElement>(node);
}
return nullptr;
@@ -127,7 +127,7 @@ bool Node::is_link() const
auto* enclosing_link = enclosing_link_element();
if (!enclosing_link)
return false;
- return enclosing_link->has_attribute("href");
+ return enclosing_link->has_attribute(HTML::AttributeNames::href);
}
void Node::dispatch_event(NonnullRefPtr<Event> event)