1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 02:47:34 +00:00

LibWeb: Store stylesheet sources as StringViews

This commit is contained in:
Sam Atkins 2023-02-17 13:00:40 +00:00 committed by Linus Groh
parent 13d2111b74
commit faab2fe101
2 changed files with 8 additions and 9 deletions

View file

@ -115,9 +115,8 @@ static CSSStyleSheet& default_stylesheet()
{ {
static JS::Handle<CSSStyleSheet> sheet; static JS::Handle<CSSStyleSheet> sheet;
if (!sheet.cell()) { if (!sheet.cell()) {
extern char const default_stylesheet_source[]; extern StringView default_stylesheet_source;
DeprecatedString css = default_stylesheet_source; sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(), default_stylesheet_source));
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(), css));
} }
return *sheet; return *sheet;
} }
@ -126,9 +125,8 @@ static CSSStyleSheet& quirks_mode_stylesheet()
{ {
static JS::Handle<CSSStyleSheet> sheet; static JS::Handle<CSSStyleSheet> sheet;
if (!sheet.cell()) { if (!sheet.cell()) {
extern char const quirks_mode_stylesheet_source[]; extern StringView quirks_mode_stylesheet_source;
DeprecatedString css = quirks_mode_stylesheet_source; sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(), quirks_mode_stylesheet_source));
sheet = JS::make_handle(parse_css_stylesheet(CSS::Parser::ParsingContext(), css));
} }
return *sheet; return *sheet;
} }

View file

@ -1,10 +1,11 @@
#!/bin/sh #!/bin/sh
echo "#include <AK/StringView.h>"
echo "namespace Web::CSS {" echo "namespace Web::CSS {"
echo "extern const char $1[];" echo "extern StringView $1;"
echo "const char $1[] = \"\\" echo "StringView $1 = \"\\"
grep -v '^ *#' < "$2" | while IFS= read -r line; do grep -v '^ *#' < "$2" | while IFS= read -r line; do
echo "$line""\\" echo "$line""\\"
done done
echo "\";" echo "\"sv;"
echo "}" echo "}"