1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 08:17:35 +00:00

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. :^)
This commit is contained in:
Sam Atkins 2021-08-20 12:08:53 +01:00 committed by Andreas Kling
parent d2342caf42
commit 6d39f4342d
2 changed files with 13 additions and 5 deletions

View file

@ -534,7 +534,11 @@ private:
class InitialStyleValue final : public StyleValue {
public:
static NonnullRefPtr<InitialStyleValue> create() { return adopt_ref(*new InitialStyleValue); }
static NonnullRefPtr<InitialStyleValue> the()
{
static NonnullRefPtr<InitialStyleValue> 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<InheritStyleValue> create() { return adopt_ref(*new InheritStyleValue); }
static NonnullRefPtr<InheritStyleValue> the()
{
static NonnullRefPtr<InheritStyleValue> instance = adopt_ref(*new InheritStyleValue);
return instance;
}
virtual ~InheritStyleValue() override { }
String to_string() const override { return "inherit"; }