mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 20:27:45 +00:00
LibWeb: Make Element::tag_name() return a const FlyString&
The more generic virtual variant is renamed to node_name() and now only Element has tag_name(). This removes a huge amount of String ctor/dtor churn in selector matching.
This commit is contained in:
parent
ea1ebe8662
commit
6242e029ed
12 changed files with 13 additions and 12 deletions
|
@ -55,7 +55,7 @@ NodeWrapper* wrap(JS::Heap& heap, Node& node)
|
||||||
NodeWrapper::NodeWrapper(Node& node)
|
NodeWrapper::NodeWrapper(Node& node)
|
||||||
: EventTargetWrapper(node)
|
: EventTargetWrapper(node)
|
||||||
{
|
{
|
||||||
put("nodeName", JS::js_string(heap(), node.tag_name()));
|
put("nodeName", JS::js_string(heap(), node.node_name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
NodeWrapper::~NodeWrapper()
|
NodeWrapper::~NodeWrapper()
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
explicit Comment(Document&, const String&);
|
explicit Comment(Document&, const String&);
|
||||||
virtual ~Comment() override;
|
virtual ~Comment() override;
|
||||||
|
|
||||||
virtual FlyString tag_name() const override { return "#comment"; }
|
virtual FlyString node_name() const override { return "#comment"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -69,7 +69,7 @@ public:
|
||||||
CSS::StyleSheetList& style_sheets() { return *m_style_sheets; }
|
CSS::StyleSheetList& style_sheets() { return *m_style_sheets; }
|
||||||
const CSS::StyleSheetList& style_sheets() const { return *m_style_sheets; }
|
const CSS::StyleSheetList& style_sheets() const { return *m_style_sheets; }
|
||||||
|
|
||||||
virtual FlyString tag_name() const override { return "#document"; }
|
virtual FlyString node_name() const override { return "#document"; }
|
||||||
|
|
||||||
void set_hovered_node(Node*);
|
void set_hovered_node(Node*);
|
||||||
Node* hovered_node() { return m_hovered_node; }
|
Node* hovered_node() { return m_hovered_node; }
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual FlyString tag_name() const override { return "#document-fragment"; }
|
virtual FlyString node_name() const override { return "#document-fragment"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
explicit DocumentType(Document&);
|
explicit DocumentType(Document&);
|
||||||
virtual ~DocumentType() override;
|
virtual ~DocumentType() override;
|
||||||
|
|
||||||
virtual FlyString tag_name() const override { return "#doctype"; }
|
virtual FlyString node_name() const override { return "#doctype"; }
|
||||||
|
|
||||||
const String& name() const { return m_name; }
|
const String& name() const { return m_name; }
|
||||||
void set_name(const String& name) { m_name = name; }
|
void set_name(const String& name) { m_name = name; }
|
||||||
|
|
|
@ -45,7 +45,8 @@ public:
|
||||||
Element(Document&, const FlyString& tag_name);
|
Element(Document&, const FlyString& tag_name);
|
||||||
virtual ~Element() override;
|
virtual ~Element() override;
|
||||||
|
|
||||||
virtual FlyString tag_name() const final { return m_tag_name; }
|
virtual FlyString node_name() const final { return m_tag_name; }
|
||||||
|
const FlyString& tag_name() const { return m_tag_name; }
|
||||||
|
|
||||||
bool has_attribute(const FlyString& name) const { return !attribute(name).is_null(); }
|
bool has_attribute(const FlyString& name) const { return !attribute(name).is_null(); }
|
||||||
String attribute(const FlyString& name) const;
|
String attribute(const FlyString& name) const;
|
||||||
|
|
|
@ -84,7 +84,7 @@ public:
|
||||||
|
|
||||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const;
|
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const;
|
||||||
|
|
||||||
virtual FlyString tag_name() const = 0;
|
virtual FlyString node_name() const = 0;
|
||||||
|
|
||||||
virtual String text_content() const;
|
virtual String text_content() const;
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ public:
|
||||||
explicit Text(Document&, const String&);
|
explicit Text(Document&, const String&);
|
||||||
virtual ~Text() override;
|
virtual ~Text() override;
|
||||||
|
|
||||||
virtual FlyString tag_name() const override { return "#text"; }
|
virtual FlyString node_name() const override { return "#text"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
virtual RefPtr<LayoutNode> create_layout_node(const StyleProperties* parent_style) const override;
|
||||||
|
|
|
@ -130,7 +130,7 @@ GUI::Variant DOMTreeModel::data(const GUI::ModelIndex& index, Role role) const
|
||||||
if (node.is_text())
|
if (node.is_text())
|
||||||
return String::format("%s", with_whitespace_collapsed(to<Text>(node).data()).characters());
|
return String::format("%s", with_whitespace_collapsed(to<Text>(node).data()).characters());
|
||||||
if (!node.is_element())
|
if (!node.is_element())
|
||||||
return node.tag_name();
|
return node.node_name();
|
||||||
auto& element = to<Element>(node);
|
auto& element = to<Element>(node);
|
||||||
StringBuilder builder;
|
StringBuilder builder;
|
||||||
builder.append('<');
|
builder.append('<');
|
||||||
|
|
|
@ -65,7 +65,7 @@ void StackingContext::dump(int indent) const
|
||||||
{
|
{
|
||||||
for (int i = 0; i < indent; ++i)
|
for (int i = 0; i < indent; ++i)
|
||||||
dbgprintf(" ");
|
dbgprintf(" ");
|
||||||
dbgprintf("SC for %s{%s} %s [children: %zu]\n", m_box.class_name(), m_box.node() ? m_box.node()->tag_name().characters() : "(anonymous)", m_box.absolute_rect().to_string().characters(), m_children.size());
|
dbgprintf("SC for %s{%s} %s [children: %zu]\n", m_box.class_name(), m_box.node() ? m_box.node()->node_name().characters() : "(anonymous)", m_box.absolute_rect().to_string().characters(), m_children.size());
|
||||||
for (auto& child : m_children)
|
for (auto& child : m_children)
|
||||||
child->dump(indent + 1);
|
child->dump(indent + 1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,7 +134,7 @@ GUI::Variant LayoutTreeModel::data(const GUI::ModelIndex& index, Role role) cons
|
||||||
if (node.is_anonymous()) {
|
if (node.is_anonymous()) {
|
||||||
builder.append("[anonymous]");
|
builder.append("[anonymous]");
|
||||||
} else if (!node.node()->is_element()) {
|
} else if (!node.node()->is_element()) {
|
||||||
builder.append(node.node()->tag_name());
|
builder.append(node.node()->node_name());
|
||||||
} else {
|
} else {
|
||||||
auto& element = to<Element>(*node.node());
|
auto& element = to<Element>(*node.node());
|
||||||
builder.append('<');
|
builder.append('<');
|
||||||
|
|
|
@ -194,7 +194,7 @@ static bool parse_html_document(const StringView& html, Document& document, Pare
|
||||||
case State::Free:
|
case State::Free:
|
||||||
if (ch == '<') {
|
if (ch == '<') {
|
||||||
bool should_treat_as_text = false;
|
bool should_treat_as_text = false;
|
||||||
if (node_stack.last().tag_name() == "script") {
|
if (node_stack.last().node_name() == "script") {
|
||||||
bool is_script_close_tag = peek(1) == '/'
|
bool is_script_close_tag = peek(1) == '/'
|
||||||
&& tolower(peek(2)) == 's'
|
&& tolower(peek(2)) == 's'
|
||||||
&& tolower(peek(3)) == 'c'
|
&& tolower(peek(3)) == 'c'
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue