From 027cbe6b891d7143e206cb824b0692b46f097d3f Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sun, 10 Oct 2021 00:06:13 -0700 Subject: [PATCH] LibWeb: Optimize CSS::StyleDeclaration for size We can reduce the amount of padding the compiler adds in order to ensure data alignment of member variables by ordering the types in a struct by size in decending order. Found By PVS-Studio: https://pvs-studio.com/en/docs/warnings/v802/ --- Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp | 2 +- Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h | 2 +- Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp index ad45162c46..0c0baddd1d 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.cpp @@ -87,9 +87,9 @@ bool PropertyOwningCSSStyleDeclaration::set_property(PropertyID property_id, Str } m_properties.append(CSS::StyleProperty { + .important = false, .property_id = property_id, .value = new_value.release_nonnull(), - .important = false, }); return true; } diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h index 92db88971e..7741e7fbb4 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleDeclaration.h @@ -14,10 +14,10 @@ namespace Web::CSS { struct StyleProperty { + bool important { false }; CSS::PropertyID property_id; NonnullRefPtr value; String custom_name {}; - bool important { false }; }; class CSSStyleDeclaration diff --git a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp index a20dc20391..de28da9894 100644 --- a/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp +++ b/Userland/Libraries/LibWeb/CSS/Parser/Parser.cpp @@ -1834,9 +1834,9 @@ Optional Parser::convert_to_style_property(StyleDeclarationRule c } if (property_id == PropertyID::Custom) { - return StyleProperty { property_id, value.release_value(), declaration.m_name, declaration.m_important }; + return StyleProperty { declaration.m_important, property_id, value.release_value(), declaration.m_name }; } else { - return StyleProperty { property_id, value.release_value(), {}, declaration.m_important }; + return StyleProperty { declaration.m_important, property_id, value.release_value(), {} }; } }