From 6d39f4342d48e0be49f217ab491407123547e99f Mon Sep 17 00:00:00 2001 From: Sam Atkins Date: Fri, 20 Aug 2021 12:08:53 +0100 Subject: LibWeb: Use single shared instance of Inherit/InitialStyleValue These are always the same, so we can avoid allocating them repeatedly and just use a single instance of each. :^) --- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 6 +++--- Userland/Libraries/LibWeb/CSS/StyleValue.h | 12 ++++++++++-- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'Userland/Libraries/LibWeb/CSS') diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index b901115d80..33fcfdb547 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1404,9 +1404,9 @@ RefPtr Parser::parse_builtin_value(ParsingContext const&, StyleCompo if (component_value.is(Token::Type::Ident)) { auto ident = component_value.token().ident(); if (ident.equals_ignoring_case("inherit")) - return InheritStyleValue::create(); + return InheritStyleValue::the(); if (ident.equals_ignoring_case("initial")) - return InitialStyleValue::create(); + return InitialStyleValue::the(); // FIXME: Implement `unset` keyword } @@ -2738,7 +2738,7 @@ RefPtr Parser::parse_text_decoration_value(ParsingContext const& con decoration_style = IdentifierStyleValue::create(ValueID::Solid); // FIXME: Should default to 'currentcolor' special value: https://www.w3.org/TR/css-color-3/#currentcolor if (!decoration_color) - decoration_color = InitialStyleValue::create(); + decoration_color = InitialStyleValue::the(); return TextDecorationStyleValue::create(decoration_line.release_nonnull(), decoration_style.release_nonnull(), decoration_color.release_nonnull()); } diff --git a/Userland/Libraries/LibWeb/CSS/StyleValue.h b/Userland/Libraries/LibWeb/CSS/StyleValue.h index e294b8988e..fb53235286 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleValue.h +++ b/Userland/Libraries/LibWeb/CSS/StyleValue.h @@ -534,7 +534,11 @@ private: class InitialStyleValue final : public StyleValue { public: - static NonnullRefPtr create() { return adopt_ref(*new InitialStyleValue); } + static NonnullRefPtr the() + { + static NonnullRefPtr instance = adopt_ref(*new InitialStyleValue); + return instance; + } virtual ~InitialStyleValue() override { } String to_string() const override { return "initial"; } @@ -548,7 +552,11 @@ private: class InheritStyleValue final : public StyleValue { public: - static NonnullRefPtr create() { return adopt_ref(*new InheritStyleValue); } + static NonnullRefPtr the() + { + static NonnullRefPtr instance = adopt_ref(*new InheritStyleValue); + return instance; + } virtual ~InheritStyleValue() override { } String to_string() const override { return "inherit"; } -- cgit v1.2.3