mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 20:15:17 +00:00
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%. :^)
This commit is contained in:
parent
39389b5704
commit
74fda2a761
Notes:
sideshowbarker
2024-07-17 17:29:34 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/74fda2a761
1 changed files with 6 additions and 4 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue