mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-05-01 20:17:13 +02:00
CodeGenerators: Use a HashMap for string to PropertyID lookups
This commit is contained in:
committed by
Andreas Kling
parent
d25f0571a9
commit
93889c5cd7
Notes:
github-actions[bot]
2025-11-08 08:30:24 +00:00
Author: https://github.com/tcl3 Commit: https://github.com/LadybirdBrowser/ladybird/commit/93889c5cd7d Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6751
@@ -444,8 +444,9 @@ ErrorOr<void> generate_implementation_file(JsonObject& properties, JsonObject& l
|
||||
|
||||
namespace Web::CSS {
|
||||
|
||||
Optional<PropertyID> property_id_from_camel_case_string(StringView string)
|
||||
static auto generate_camel_case_property_table()
|
||||
{
|
||||
HashMap<StringView, PropertyID, CaseInsensitiveASCIIStringViewTraits> table;
|
||||
)~~~");
|
||||
|
||||
properties.for_each_member([&](auto& name, auto& value) {
|
||||
@@ -460,20 +461,24 @@ Optional<PropertyID> property_id_from_camel_case_string(StringView string)
|
||||
member_generator.set("name:titlecase", title_casify(name));
|
||||
}
|
||||
member_generator.append(R"~~~(
|
||||
if (string.equals_ignoring_ascii_case("@name:camelcase@"sv))
|
||||
return PropertyID::@name:titlecase@;
|
||||
table.set("@name:camelcase@"sv, PropertyID::@name:titlecase@);
|
||||
)~~~");
|
||||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
return {};
|
||||
return table;
|
||||
}
|
||||
|
||||
Optional<PropertyID> property_id_from_string(StringView string)
|
||||
{
|
||||
if (is_a_custom_property_name_string(string))
|
||||
return PropertyID::Custom;
|
||||
static HashMap<StringView, PropertyID, CaseInsensitiveASCIIStringViewTraits> const camel_case_properties_table = generate_camel_case_property_table();
|
||||
|
||||
Optional<PropertyID> property_id_from_camel_case_string(StringView string)
|
||||
{
|
||||
return camel_case_properties_table.get(string);
|
||||
}
|
||||
|
||||
static auto generate_properties_table()
|
||||
{
|
||||
HashMap<StringView, PropertyID, CaseInsensitiveASCIIStringViewTraits> table;
|
||||
)~~~");
|
||||
|
||||
properties.for_each_member([&](auto& name, auto& value) {
|
||||
@@ -487,13 +492,22 @@ Optional<PropertyID> property_id_from_string(StringView string)
|
||||
member_generator.set("name:titlecase", title_casify(name));
|
||||
}
|
||||
member_generator.append(R"~~~(
|
||||
if (string.equals_ignoring_ascii_case("@name@"sv))
|
||||
return PropertyID::@name:titlecase@;
|
||||
table.set("@name@"sv, PropertyID::@name:titlecase@);
|
||||
)~~~");
|
||||
});
|
||||
|
||||
generator.append(R"~~~(
|
||||
return {};
|
||||
return table;
|
||||
}
|
||||
|
||||
static HashMap<StringView, PropertyID, CaseInsensitiveASCIIStringViewTraits> const properties_table = generate_properties_table();
|
||||
|
||||
Optional<PropertyID> property_id_from_string(StringView string)
|
||||
{
|
||||
if (is_a_custom_property_name_string(string))
|
||||
return PropertyID::Custom;
|
||||
|
||||
return properties_table.get(string);
|
||||
}
|
||||
|
||||
FlyString const& string_from_property_id(PropertyID property_id) {
|
||||
|
||||
Reference in New Issue
Block a user