LibUnicode: Remove now unused value-from-string generator overload

The generate_value_from_string_for_dynamic_loading() overload was just
temporary until all generates were switched over to dynamic loading.
This commit is contained in:
Timothy Flynn 2021-12-15 23:23:52 -05:00 committed by Brian Gianforcaro
parent 15e1498419
commit 52394deece
Notes: sideshowbarker 2024-07-17 22:27:33 +09:00
3 changed files with 3 additions and 56 deletions

View file

@ -921,7 +921,7 @@ bool code_point_has_@enum_snake@(u32 code_point, @enum_title@ @enum_snake@)
for (auto const& alias : aliases)
hashes.set(alias.alias.hash(), alias.alias);
generate_value_from_string_for_dynamic_loading(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
};
append_prop_search("GeneralCategory"sv, "general_category"sv, "s_general_categories"sv);

View file

@ -1068,7 +1068,7 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
for (auto const& alias : aliases)
hashes.set(alias.alias.hash(), format_identifier(enum_title, alias.alias));
generate_value_from_string_for_dynamic_loading(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
generate_value_from_string(generator, "{}_from_string"sv, enum_title, enum_snake, move(hashes));
};
auto append_alias_search = [&](StringView enum_snake, auto const& aliases) {
@ -1078,7 +1078,7 @@ Optional<StringView> get_locale_@enum_snake@_mapping(StringView locale, StringVi
for (auto const& alias : aliases)
hashes.set(alias.key.hash(), alias.value);
generate_value_from_string_for_dynamic_loading(generator, "resolve_{}_alias"sv, s_string_index_type, enum_snake, move(hashes), "StringView"sv, "s_string_list[{}]"sv);
generate_value_from_string(generator, "resolve_{}_alias"sv, s_string_index_type, enum_snake, move(hashes), "StringView"sv, "s_string_list[{}]"sv);
};
append_from_string("Locale"sv, "locale"sv, locale_data.locales.keys(), locale_data.locale_aliases);

View file

@ -304,59 +304,6 @@ void generate_value_from_string(SourceGenerator& generator, StringView method_na
generator.set("return_type", return_type.has_value() ? *return_type : value_type);
generator.set("size", String::number(hashes.size()));
generator.append(R"~~~(
Optional<@return_type@> @method_name@(StringView key)
{
constexpr Array<HashValuePair<@value_type@>, @size@> hash_pairs { {
)~~~");
auto hash_keys = hashes.keys();
quick_sort(hash_keys);
constexpr size_t max_values_per_row = 10;
size_t values_in_current_row = 0;
for (auto hash_key : hash_keys) {
if (values_in_current_row++ > 0)
generator.append(" ");
if constexpr (IsIntegral<ValueType>)
generator.set("value"sv, String::number(hashes.get(hash_key).value()));
else
generator.set("value"sv, String::formatted("{}::{}", value_type, hashes.get(hash_key).value()));
generator.set("hash"sv, String::number(hash_key));
generator.append("{ @hash@U, @value@ },"sv);
if (values_in_current_row == max_values_per_row) {
generator.append("\n ");
values_in_current_row = 0;
}
}
generator.set("return_statement", String::formatted(return_format, "value->value"sv));
generator.append(R"~~~(
} };
if (auto const* value = binary_search(hash_pairs, key.hash(), nullptr, HashValueComparator<@value_type@> {}))
return @return_statement@;
return {};
}
)~~~");
}
// This is a temporary duplicate of generate_value_from_string() until all generators support dynamic loading.
template<typename ValueType>
void generate_value_from_string_for_dynamic_loading(SourceGenerator& generator, StringView method_name_format, StringView value_type, StringView value_name, HashValueMap<ValueType> hashes, Optional<StringView> return_type = {}, StringView return_format = "{}"sv)
{
ensure_from_string_types_are_generated(generator);
generator.set("method_name", String::formatted(method_name_format, value_name));
generator.set("value_type", value_type);
generator.set("value_name", value_name);
generator.set("return_type", return_type.has_value() ? *return_type : value_type);
generator.set("size", String::number(hashes.size()));
generator.append(R"~~~(
Optional<@return_type@> @method_name@(StringView key) asm("unicode_@method_name@");
Optional<@return_type@> @method_name@(StringView key)