mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:17:35 +00:00
LibWeb+LibJS: Move some code around to make CSS/Parser parse faster
This makes it possible to include fewer full definitions of things, which makes the file about 30% faster to compile.
This commit is contained in:
parent
392b5c3b19
commit
06c6c40df9
28 changed files with 117 additions and 64 deletions
|
@ -12,7 +12,6 @@
|
|||
#include <AK/Debug.h>
|
||||
#include <AK/GenericLexer.h>
|
||||
#include <AK/SourceLocation.h>
|
||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||
#include <LibWeb/CSS/CSSFontFaceRule.h>
|
||||
#include <LibWeb/CSS/CSSImportRule.h>
|
||||
#include <LibWeb/CSS/CSSKeyframeRule.h>
|
||||
|
@ -84,7 +83,6 @@
|
|||
#include <LibWeb/CSS/StyleValues/URLStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/UnresolvedStyleValue.h>
|
||||
#include <LibWeb/CSS/StyleValues/UnsetStyleValue.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/Infra/Strings.h>
|
||||
|
||||
|
@ -95,43 +93,6 @@ static void log_parse_error(SourceLocation const& location = SourceLocation::cur
|
|||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
ParsingContext::ParsingContext(JS::Realm& realm)
|
||||
: m_realm(realm)
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url)
|
||||
: m_realm(const_cast<JS::Realm&>(document.realm()))
|
||||
, m_document(&document)
|
||||
, m_url(move(url))
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document)
|
||||
: m_realm(const_cast<JS::Realm&>(document.realm()))
|
||||
, m_document(&document)
|
||||
, m_url(document.url())
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::ParentNode& parent_node)
|
||||
: m_realm(parent_node.realm())
|
||||
, m_document(&parent_node.document())
|
||||
, m_url(parent_node.document().url())
|
||||
{
|
||||
}
|
||||
|
||||
bool ParsingContext::in_quirks_mode() const
|
||||
{
|
||||
return m_document ? m_document->in_quirks_mode() : false;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-values-4/#relative-urls
|
||||
AK::URL ParsingContext::complete_url(StringView relative_url) const
|
||||
{
|
||||
return m_url.complete_url(relative_url);
|
||||
}
|
||||
|
||||
ErrorOr<Parser> Parser::create(ParsingContext const& context, StringView input, StringView encoding)
|
||||
{
|
||||
auto tokens = TRY(Tokenizer::tokenize(input, encoding));
|
||||
|
@ -9279,7 +9240,7 @@ CSS::Length CSS::Parser::Parser::parse_as_sizes_attribute()
|
|||
// If it does not parse correctly, or it does parse correctly but the <media-condition> evaluates to false, continue.
|
||||
TokenStream<ComponentValue> token_stream { unparsed_size };
|
||||
auto media_condition = parse_media_condition(token_stream, MediaCondition::AllowOr::Yes);
|
||||
if (media_condition && media_condition->evaluate(m_context.document()->window()) == CSS::MatchResult::True) {
|
||||
if (media_condition && media_condition->evaluate(*m_context.window()) == CSS::MatchResult::True) {
|
||||
return size.value();
|
||||
} else {
|
||||
continue;
|
||||
|
|
|
@ -44,6 +44,7 @@ public:
|
|||
|
||||
bool in_quirks_mode() const;
|
||||
DOM::Document const* document() const { return m_document; }
|
||||
HTML::Window const* window() const;
|
||||
AK::URL complete_url(StringView) const;
|
||||
|
||||
PropertyID current_property_id() const { return m_current_property_id; }
|
||||
|
|
58
Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp
Normal file
58
Userland/Libraries/LibWeb/CSS/Parser/ParsingContext.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Copyright (c) 2018-2022, Andreas Kling <kling@serenityos.org>
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021-2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021, Tobias Christiansen <tobyase@serenityos.org>
|
||||
* Copyright (c) 2022, MacDue <macdue@dueutil.tech>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/CSS/Parser/Parser.h>
|
||||
#include <LibWeb/DOM/Document.h>
|
||||
|
||||
namespace Web::CSS::Parser {
|
||||
|
||||
ParsingContext::ParsingContext(JS::Realm& realm)
|
||||
: m_realm(realm)
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document, AK::URL url)
|
||||
: m_realm(const_cast<JS::Realm&>(document.realm()))
|
||||
, m_document(&document)
|
||||
, m_url(move(url))
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::Document const& document)
|
||||
: m_realm(const_cast<JS::Realm&>(document.realm()))
|
||||
, m_document(&document)
|
||||
, m_url(document.url())
|
||||
{
|
||||
}
|
||||
|
||||
ParsingContext::ParsingContext(DOM::ParentNode& parent_node)
|
||||
: m_realm(parent_node.realm())
|
||||
, m_document(&parent_node.document())
|
||||
, m_url(parent_node.document().url())
|
||||
{
|
||||
}
|
||||
|
||||
bool ParsingContext::in_quirks_mode() const
|
||||
{
|
||||
return m_document ? m_document->in_quirks_mode() : false;
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/css-values-4/#relative-urls
|
||||
AK::URL ParsingContext::complete_url(StringView relative_url) const
|
||||
{
|
||||
return m_url.complete_url(relative_url);
|
||||
}
|
||||
|
||||
HTML::Window const* ParsingContext::window() const
|
||||
{
|
||||
return m_document ? &m_document->window() : nullptr;
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue