mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 14:07:45 +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
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)
|
NonnullRefPtr<StyleValue> property_initial_value(PropertyID property_id)
|
||||||
{
|
{
|
||||||
static HashMap<PropertyID, NonnullRefPtr<StyleValue>> initial_values;
|
static Array<RefPtr<StyleValue>, to_underlying(last_property_id) + 1> initial_values;
|
||||||
if (initial_values.is_empty()) {
|
static bool initialized = false;
|
||||||
|
if (!initialized) {
|
||||||
|
initialized = true;
|
||||||
ParsingContext parsing_context;
|
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@);
|
auto parsed_value = Parser(parsing_context, "@initial_value_string@").parse_as_css_value(PropertyID::@name:titlecase@);
|
||||||
VERIFY(!parsed_value.is_null());
|
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"~~~(
|
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)
|
bool property_has_quirk(PropertyID property_id, Quirk quirk)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue