From 8126cb25457a0a0bcbee8b5250eff1ee3eaf9a89 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Wed, 12 Jan 2022 17:19:59 -0500 Subject: [PATCH] LibJS+LibUnicode: Remove unnecessary locale currency mapping wrapper Before LibUnicode generated methods were weakly linked, we had a public method (get_locale_currency_mapping) for retrieving currency mappings. That method invoked one of several style-specific methods that only existed in the generated UnicodeLocale. One caveat of weakly linked functions is that every such function must have a public declaration. The result is that each of those styled methods are declared publicly, which makes the wrapper redundant because it is just as easy to invoke the method for the desired style. --- .../Runtime/Intl/DisplayNamesPrototype.cpp | 6 +++--- .../LibJS/Runtime/Intl/NumberFormat.cpp | 8 ++++---- Userland/Libraries/LibUnicode/Locale.cpp | 17 ----------------- Userland/Libraries/LibUnicode/Locale.h | 1 - 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp index 16d169ce28..8633841cea 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/DisplayNamesPrototype.cpp @@ -65,13 +65,13 @@ JS_DEFINE_NATIVE_FUNCTION(DisplayNamesPrototype::of) case DisplayNames::Type::Currency: switch (display_names->style()) { case DisplayNames::Style::Long: - result = Unicode::get_locale_currency_mapping(display_names->locale(), code.as_string().string(), Unicode::Style::Long); + result = Unicode::get_locale_long_currency_mapping(display_names->locale(), code.as_string().string()); break; case DisplayNames::Style::Short: - result = Unicode::get_locale_currency_mapping(display_names->locale(), code.as_string().string(), Unicode::Style::Short); + result = Unicode::get_locale_short_currency_mapping(display_names->locale(), code.as_string().string()); break; case DisplayNames::Style::Narrow: - result = Unicode::get_locale_currency_mapping(display_names->locale(), code.as_string().string(), Unicode::Style::Narrow); + result = Unicode::get_locale_narrow_currency_mapping(display_names->locale(), code.as_string().string()); break; default: VERIFY_NOT_REACHED(); diff --git a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp index a1f5b3cc1f..046fb92cca 100644 --- a/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp +++ b/Userland/Libraries/LibJS/Runtime/Intl/NumberFormat.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021, Tim Flynn + * Copyright (c) 2021-2022, Tim Flynn * * SPDX-License-Identifier: BSD-2-Clause */ @@ -85,13 +85,13 @@ StringView NumberFormat::resolve_currency_display() m_resolved_currency_display = currency(); break; case NumberFormat::CurrencyDisplay::Symbol: - m_resolved_currency_display = Unicode::get_locale_currency_mapping(data_locale(), currency(), Unicode::Style::Short); + m_resolved_currency_display = Unicode::get_locale_short_currency_mapping(data_locale(), currency()); break; case NumberFormat::CurrencyDisplay::NarrowSymbol: - m_resolved_currency_display = Unicode::get_locale_currency_mapping(data_locale(), currency(), Unicode::Style::Narrow); + m_resolved_currency_display = Unicode::get_locale_narrow_currency_mapping(data_locale(), currency()); break; case NumberFormat::CurrencyDisplay::Name: - m_resolved_currency_display = Unicode::get_locale_currency_mapping(data_locale(), currency(), Unicode::Style::Numeric); + m_resolved_currency_display = Unicode::get_locale_numeric_currency_mapping(data_locale(), currency()); break; default: VERIFY_NOT_REACHED(); diff --git a/Userland/Libraries/LibUnicode/Locale.cpp b/Userland/Libraries/LibUnicode/Locale.cpp index e0362979e8..a315a2db7b 100644 --- a/Userland/Libraries/LibUnicode/Locale.cpp +++ b/Userland/Libraries/LibUnicode/Locale.cpp @@ -762,23 +762,6 @@ Optional __attribute__((weak)) get_locale_calendar_mapping(StringVie Optional __attribute__((weak)) get_locale_long_date_field_mapping(StringView, StringView) { return {}; } Optional __attribute__((weak)) get_locale_short_date_field_mapping(StringView, StringView) { return {}; } Optional __attribute__((weak)) get_locale_narrow_date_field_mapping(StringView, StringView) { return {}; } - -Optional get_locale_currency_mapping(StringView locale, StringView currency, Style style) -{ - switch (style) { - case Style::Long: - return get_locale_long_currency_mapping(locale, currency); - case Style::Short: - return get_locale_short_currency_mapping(locale, currency); - case Style::Narrow: - return get_locale_narrow_currency_mapping(locale, currency); - case Style::Numeric: - return get_locale_numeric_currency_mapping(locale, currency); - default: - VERIFY_NOT_REACHED(); - } -} - Optional __attribute__((weak)) get_locale_key_mapping(StringView, StringView) { return {}; } Vector get_locale_key_mapping_list(StringView locale, StringView keyword) diff --git a/Userland/Libraries/LibUnicode/Locale.h b/Userland/Libraries/LibUnicode/Locale.h index a26aae8356..e6d7647f4e 100644 --- a/Userland/Libraries/LibUnicode/Locale.h +++ b/Userland/Libraries/LibUnicode/Locale.h @@ -159,7 +159,6 @@ Optional get_locale_long_currency_mapping(StringView locale, StringV Optional get_locale_short_currency_mapping(StringView locale, StringView currency); Optional get_locale_narrow_currency_mapping(StringView locale, StringView currency); Optional get_locale_numeric_currency_mapping(StringView locale, StringView currency); -Optional get_locale_currency_mapping(StringView locale, StringView currency, Style style); Optional get_locale_calendar_mapping(StringView locale, StringView calendar); Optional get_locale_long_date_field_mapping(StringView locale, StringView date_field); Optional get_locale_short_date_field_mapping(StringView locale, StringView date_field);