mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
LibHTML: Make the CSS and HTML parsers take StringViews
This allows us to avoid unnecessary making unnecessary String copies of all the source text.
This commit is contained in:
parent
71e8ddcd1c
commit
edbf09ea29
6 changed files with 10 additions and 10 deletions
|
@ -27,7 +27,7 @@ void HTMLLinkElement::inserted_into(Node&)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto data = file->read_all();
|
auto data = file->read_all();
|
||||||
auto sheet = parse_css(String::copy(data));
|
auto sheet = parse_css(data);
|
||||||
|
|
||||||
if (!sheet) {
|
if (!sheet) {
|
||||||
dbg() << "Failed to parse " << url.to_string();
|
dbg() << "Failed to parse " << url.to_string();
|
||||||
|
|
|
@ -178,7 +178,7 @@ void HtmlView::load(const URL& url)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String html = String::copy(f->read_all());
|
auto html = f->read_all();
|
||||||
auto document = parse_html(html, url);
|
auto document = parse_html(html, url);
|
||||||
document->normalize();
|
document->normalize();
|
||||||
|
|
||||||
|
|
|
@ -301,16 +301,16 @@ private:
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
|
|
||||||
String css;
|
StringView css;
|
||||||
};
|
};
|
||||||
|
|
||||||
NonnullRefPtr<StyleSheet> parse_css(const String& css)
|
NonnullRefPtr<StyleSheet> parse_css(const StringView& css)
|
||||||
{
|
{
|
||||||
CSSParser parser(css);
|
CSSParser parser(css);
|
||||||
return parser.parse_sheet();
|
return parser.parse_sheet();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<StyleDeclaration> parse_css_declaration(const String& css)
|
NonnullRefPtr<StyleDeclaration> parse_css_declaration(const StringView& css)
|
||||||
{
|
{
|
||||||
CSSParser parser(css);
|
CSSParser parser(css);
|
||||||
return parser.parse_standalone_declaration();
|
return parser.parse_standalone_declaration();
|
||||||
|
|
|
@ -3,6 +3,6 @@
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <LibHTML/CSS/StyleSheet.h>
|
#include <LibHTML/CSS/StyleSheet.h>
|
||||||
|
|
||||||
NonnullRefPtr<StyleSheet> parse_css(const String&);
|
NonnullRefPtr<StyleSheet> parse_css(const StringView&);
|
||||||
NonnullRefPtr<StyleDeclaration> parse_css_declaration(const String&);
|
NonnullRefPtr<StyleDeclaration> parse_css_declaration(const StringView&);
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ static bool is_valid_in_attribute_name(char ch)
|
||||||
return isalnum(ch) || ch == '_' || ch == '-';
|
return isalnum(ch) || ch == '_' || ch == '-';
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool is_self_closing_tag(const String& tag_name)
|
static bool is_self_closing_tag(const StringView& tag_name)
|
||||||
{
|
{
|
||||||
return tag_name == "area"
|
return tag_name == "area"
|
||||||
|| tag_name == "base"
|
|| tag_name == "base"
|
||||||
|
@ -75,7 +75,7 @@ static bool is_self_closing_tag(const String& tag_name)
|
||||||
|| tag_name == "wbr";
|
|| tag_name == "wbr";
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<Document> parse_html(const String& html, const URL& url)
|
NonnullRefPtr<Document> parse_html(const StringView& html, const URL& url)
|
||||||
{
|
{
|
||||||
NonnullRefPtrVector<ParentNode> node_stack;
|
NonnullRefPtrVector<ParentNode> node_stack;
|
||||||
|
|
||||||
|
|
|
@ -3,5 +3,5 @@
|
||||||
#include <AK/NonnullRefPtr.h>
|
#include <AK/NonnullRefPtr.h>
|
||||||
#include <LibHTML/DOM/Document.h>
|
#include <LibHTML/DOM/Document.h>
|
||||||
|
|
||||||
NonnullRefPtr<Document> parse_html(const String&, const URL& = URL());
|
NonnullRefPtr<Document> parse_html(const StringView&, const URL& = URL());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue