diff options
author | Andreas Kling <kling@serenityos.org> | 2022-03-13 17:15:58 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-13 18:09:43 +0100 |
commit | 74fda2a7618b00920371ca5e4689c3c3907495d2 (patch) | |
tree | ea696e887a617229b1fb2bc02df6f1ed02f0d441 /Meta | |
parent | 39389b5704a74cb6269905b3eeb6f58332a1d982 (diff) | |
download | serenity-74fda2a7618b00920371ca5e4689c3c3907495d2.zip |
LibWeb: Make CSS::property_initial_value() use an Array internally
Since we want to store an initial value for every CSS::PropertyID,
it's pretty silly to use a HashMap when we can use an Array.
This takes the function from ~2.8% when mousing around on GitHub all the
way down to ~0.6%. :^)
Diffstat (limited to 'Meta')
-rw-r--r-- | Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp index c0da7e33f4..d82e9efdfc 100644 --- a/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp +++ b/Meta/Lagom/Tools/CodeGenerators/LibWeb/Generate_CSS_PropertyID_cpp.cpp @@ -129,8 +129,10 @@ bool is_inherited_property(PropertyID property_id) NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id) { - static HashMap<PropertyID, NonnullRefPtr<StyleValue>> initial_values; - if (initial_values.is_empty()) { + static Array<RefPtr<StyleValue>, to_underlying(last_property_id) + 1> initial_values; + static bool initialized = false; + if (!initialized) { + initialized = true; ParsingContext parsing_context; )~~~"); @@ -155,7 +157,7 @@ NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id) { auto parsed_value = Parser(parsing_context, "@initial_value_string@").parse_as_css_value(PropertyID::@name:titlecase@); VERIFY(!parsed_value.is_null()); - initial_values.set(PropertyID::@name:titlecase@, parsed_value.release_nonnull()); + initial_values[to_underlying(PropertyID::@name:titlecase@)] = parsed_value.release_nonnull(); } )~~~"); }; @@ -177,7 +179,7 @@ NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id) generator.append(R"~~~( } - return *initial_values.find(property_id)->value; + return *initial_values[to_underlying(property_id)]; } bool property_has_quirk(PropertyID property_id, Quirk quirk) |