mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 01:07:35 +00:00
LibWeb: Use FlyString for element attribute names
Attribute names occur again and again.
This commit is contained in:
parent
26bc3d4ea0
commit
7f83f77377
6 changed files with 19 additions and 18 deletions
|
@ -49,7 +49,7 @@ Element::~Element()
|
|||
{
|
||||
}
|
||||
|
||||
Attribute* Element::find_attribute(const String& name)
|
||||
Attribute* Element::find_attribute(const FlyString& name)
|
||||
{
|
||||
for (auto& attribute : m_attributes) {
|
||||
if (attribute.name() == name)
|
||||
|
@ -58,7 +58,7 @@ Attribute* Element::find_attribute(const String& name)
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
const Attribute* Element::find_attribute(const String& name) const
|
||||
const Attribute* Element::find_attribute(const FlyString& name) const
|
||||
{
|
||||
for (auto& attribute : m_attributes) {
|
||||
if (attribute.name() == name)
|
||||
|
@ -67,14 +67,14 @@ const Attribute* Element::find_attribute(const String& name) const
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
String Element::attribute(const String& name) const
|
||||
String Element::attribute(const FlyString& name) const
|
||||
{
|
||||
if (auto* attribute = find_attribute(name))
|
||||
return attribute->value();
|
||||
return {};
|
||||
}
|
||||
|
||||
void Element::set_attribute(const String& name, const String& value)
|
||||
void Element::set_attribute(const FlyString& name, const String& value)
|
||||
{
|
||||
if (auto* attribute = find_attribute(name))
|
||||
attribute->set_value(value);
|
||||
|
@ -131,7 +131,7 @@ RefPtr<LayoutNode> Element::create_layout_node(const StyleProperties* parent_sty
|
|||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void Element::parse_attribute(const String&, const String&)
|
||||
void Element::parse_attribute(const FlyString&, const String&)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <AK/FlyString.h>
|
||||
#include <AK/String.h>
|
||||
#include <LibWeb/DOM/ParentNode.h>
|
||||
#include <LibWeb/Layout/LayoutNode.h>
|
||||
|
@ -36,19 +37,19 @@ class LayoutNodeWithStyle;
|
|||
|
||||
class Attribute {
|
||||
public:
|
||||
Attribute(const String& name, const String& value)
|
||||
Attribute(const FlyString& name, const String& value)
|
||||
: m_name(name)
|
||||
, m_value(value)
|
||||
{
|
||||
}
|
||||
|
||||
const String& name() const { return m_name; }
|
||||
const FlyString& name() const { return m_name; }
|
||||
const String& value() const { return m_value; }
|
||||
|
||||
void set_value(const String& value) { m_value = value; }
|
||||
|
||||
private:
|
||||
String m_name;
|
||||
FlyString m_name;
|
||||
String m_value;
|
||||
};
|
||||
|
||||
|
@ -59,9 +60,9 @@ public:
|
|||
|
||||
virtual String tag_name() const final { return m_tag_name; }
|
||||
|
||||
bool has_attribute(const String& name) const { return !attribute(name).is_null(); }
|
||||
String attribute(const String& name) const;
|
||||
void set_attribute(const String& name, const String& value);
|
||||
bool has_attribute(const FlyString& name) const { return !attribute(name).is_null(); }
|
||||
String attribute(const FlyString& name) const;
|
||||
void set_attribute(const FlyString& name, const String& value);
|
||||
|
||||
void set_attributes(Vector<Attribute>&&);
|
||||
|
||||
|
@ -75,7 +76,7 @@ public:
|
|||
bool has_class(const StringView&) const;
|
||||
|
||||
virtual void apply_presentational_hints(StyleProperties&) const {}
|
||||
virtual void parse_attribute(const String& name, const String& value);
|
||||
virtual void parse_attribute(const FlyString& name, const String& value);
|
||||
|
||||
void recompute_style();
|
||||
|
||||
|
@ -90,8 +91,8 @@ public:
|
|||
private:
|
||||
RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
||||
|
||||
Attribute* find_attribute(const String& name);
|
||||
const Attribute* find_attribute(const String& name) const;
|
||||
Attribute* find_attribute(const FlyString& name);
|
||||
const Attribute* find_attribute(const FlyString& name) const;
|
||||
|
||||
String m_tag_name;
|
||||
Vector<Attribute> m_attributes;
|
||||
|
|
|
@ -58,7 +58,7 @@ void HTMLBodyElement::apply_presentational_hints(StyleProperties& style) const
|
|||
});
|
||||
}
|
||||
|
||||
void HTMLBodyElement::parse_attribute(const String& name, const String& value)
|
||||
void HTMLBodyElement::parse_attribute(const FlyString& name, const String& value)
|
||||
{
|
||||
if (name.equals_ignoring_case("link")) {
|
||||
auto color = Color::from_string(value);
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
HTMLBodyElement(Document&, const String& tag_name);
|
||||
virtual ~HTMLBodyElement() override;
|
||||
|
||||
virtual void parse_attribute(const String&, const String&) override;
|
||||
virtual void parse_attribute(const FlyString&, const String&) override;
|
||||
virtual void apply_presentational_hints(StyleProperties&) const override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ HTMLImageElement::~HTMLImageElement()
|
|||
{
|
||||
}
|
||||
|
||||
void HTMLImageElement::parse_attribute(const String& name, const String& value)
|
||||
void HTMLImageElement::parse_attribute(const FlyString& name, const String& value)
|
||||
{
|
||||
if (name.equals_ignoring_case("src"))
|
||||
load_image(value);
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
HTMLImageElement(Document&, const String& tag_name);
|
||||
virtual ~HTMLImageElement() override;
|
||||
|
||||
virtual void parse_attribute(const String& name, const String& value) override;
|
||||
virtual void parse_attribute(const FlyString& name, const String& value) override;
|
||||
|
||||
String alt() const { return attribute("alt"); }
|
||||
String src() const { return attribute("src"); }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue