mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 20:28:11 +00:00
LibWeb: Make StyleComponentValueRule use a Variant
This shrinks its size from 96 bytes to 80. It's now limited by the size of Token.
This commit is contained in:
parent
ca1b855d99
commit
218a9af6b3
2 changed files with 27 additions and 64 deletions
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Copyright (c) 2020-2021, the SerenityOS developers.
|
||||
* Copyright (c) 2021, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2021-2022, Sam Atkins <atkinssj@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -20,46 +20,26 @@ class StyleComponentValueRule {
|
|||
friend class Parser;
|
||||
|
||||
public:
|
||||
enum class ComponentType {
|
||||
Token,
|
||||
Function,
|
||||
Block
|
||||
};
|
||||
|
||||
StyleComponentValueRule(Token);
|
||||
explicit StyleComponentValueRule(NonnullRefPtr<StyleFunctionRule>);
|
||||
explicit StyleComponentValueRule(NonnullRefPtr<StyleBlockRule>);
|
||||
~StyleComponentValueRule();
|
||||
|
||||
bool is_block() const { return m_type == ComponentType::Block; }
|
||||
StyleBlockRule const& block() const
|
||||
{
|
||||
VERIFY(is_block());
|
||||
return *m_block;
|
||||
}
|
||||
bool is_block() const { return m_value.has<NonnullRefPtr<StyleBlockRule>>(); }
|
||||
StyleBlockRule const& block() const { return m_value.get<NonnullRefPtr<StyleBlockRule>>(); }
|
||||
|
||||
bool is_function() const { return m_type == ComponentType::Function; }
|
||||
StyleFunctionRule const& function() const
|
||||
{
|
||||
VERIFY(is_function());
|
||||
return *m_function;
|
||||
}
|
||||
bool is_function() const { return m_value.has<NonnullRefPtr<StyleFunctionRule>>(); }
|
||||
StyleFunctionRule const& function() const { return m_value.get<NonnullRefPtr<StyleFunctionRule>>(); }
|
||||
|
||||
bool is_token() const { return m_type == ComponentType::Token; }
|
||||
bool is(Token::Type type) const
|
||||
{
|
||||
return m_type == ComponentType::Token && m_token.is(type);
|
||||
}
|
||||
Token const& token() const { return m_token; }
|
||||
operator Token() const { return m_token; }
|
||||
bool is_token() const { return m_value.has<Token>(); }
|
||||
bool is(Token::Type type) const { return is_token() && token().is(type); }
|
||||
Token const& token() const { return m_value.get<Token>(); }
|
||||
operator Token() const { return m_value.get<Token>(); }
|
||||
|
||||
String to_string() const;
|
||||
String to_debug_string() const;
|
||||
|
||||
private:
|
||||
ComponentType m_type;
|
||||
Token m_token;
|
||||
RefPtr<StyleFunctionRule> m_function;
|
||||
RefPtr<StyleBlockRule> m_block;
|
||||
Variant<Token, NonnullRefPtr<StyleFunctionRule>, NonnullRefPtr<StyleBlockRule>> m_value;
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue