From 746dddc0673d7261f19b1e056e90e6e3a49ef33a Mon Sep 17 00:00:00 2001 From: reduz Date: Fri, 13 May 2022 15:04:37 +0200 Subject: Replace most uses of Map by HashMap * Map is unnecessary and inefficient in almost every case. * Replaced by the new HashMap. * Renamed Map to RBMap and Set to RBSet for cases that still make sense (order matters) but use is discouraged. There were very few cases where replacing by HashMap was undesired because keeping the key order was intended. I tried to keep those (as RBMap) as much as possible, but might have missed some. Review appreciated! --- core/string/translation.cpp | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) (limited to 'core/string/translation.cpp') diff --git a/core/string/translation.cpp b/core/string/translation.cpp index d6d361b5f1..c64f815563 100644 --- a/core/string/translation.cpp +++ b/core/string/translation.cpp @@ -95,12 +95,12 @@ StringName Translation::get_message(const StringName &p_src_text, const StringNa WARN_PRINT("Translation class doesn't handle context. Using context in get_message() on a Translation instance is probably a mistake. \nUse a derived Translation class that handles context, such as TranslationPO class"); } - const Map::Element *E = translation_map.find(p_src_text); + HashMap::ConstIterator E = translation_map.find(p_src_text); if (!E) { return StringName(); } - return E->get(); + return E->value; } StringName Translation::get_plural_message(const StringName &p_src_text, const StringName &p_plural_text, int p_n, const StringName &p_context) const { @@ -215,12 +215,12 @@ static _character_accent_pair _character_to_accented[] = { Vector TranslationServer::locale_script_info; -Map TranslationServer::language_map; -Map TranslationServer::script_map; -Map TranslationServer::locale_rename_map; -Map TranslationServer::country_name_map; -Map TranslationServer::variant_map; -Map TranslationServer::country_rename_map; +HashMap TranslationServer::language_map; +HashMap TranslationServer::script_map; +HashMap TranslationServer::locale_rename_map; +HashMap TranslationServer::country_name_map; +HashMap TranslationServer::variant_map; +HashMap TranslationServer::country_rename_map; void TranslationServer::init_locale_info() { // Init locale info. @@ -452,8 +452,8 @@ String TranslationServer::get_locale_name(const String &p_locale) const { Vector TranslationServer::get_all_languages() const { Vector languages; - for (const Map::Element *E = language_map.front(); E; E = E->next()) { - languages.push_back(E->key()); + for (const KeyValue &E : language_map) { + languages.push_back(E.key); } return languages; @@ -466,8 +466,8 @@ String TranslationServer::get_language_name(const String &p_language) const { Vector TranslationServer::get_all_scripts() const { Vector scripts; - for (const Map::Element *E = script_map.front(); E; E = E->next()) { - scripts.push_back(E->key()); + for (const KeyValue &E : script_map) { + scripts.push_back(E.key); } return scripts; @@ -480,8 +480,8 @@ String TranslationServer::get_script_name(const String &p_script) const { Vector TranslationServer::get_all_countries() const { Vector countries; - for (const Map::Element *E = country_name_map.front(); E; E = E->next()) { - countries.push_back(E->key()); + for (const KeyValue &E : country_name_map) { + countries.push_back(E.key); } return countries; @@ -507,7 +507,7 @@ String TranslationServer::get_locale() const { Array TranslationServer::get_loaded_locales() const { Array locales; - for (const Set>::Element *E = translations.front(); E; E = E->next()) { + for (const RBSet>::Element *E = translations.front(); E; E = E->next()) { const Ref &t = E->get(); ERR_FAIL_COND_V(t.is_null(), Array()); String l = t->get_locale(); @@ -530,7 +530,7 @@ Ref TranslationServer::get_translation_object(const String &p_local Ref res; int best_score = 0; - for (const Set>::Element *E = translations.front(); E; E = E->next()) { + for (const RBSet>::Element *E = translations.front(); E; E = E->next()) { const Ref &t = E->get(); ERR_FAIL_COND_V(t.is_null(), nullptr); String l = t->get_locale(); @@ -599,7 +599,7 @@ StringName TranslationServer::_get_message_from_translations(const StringName &p StringName res; int best_score = 0; - for (const Set>::Element *E = translations.front(); E; E = E->next()) { + for (const RBSet>::Element *E = translations.front(); E; E = E->next()) { const Ref &t = E->get(); ERR_FAIL_COND_V(t.is_null(), p_message); String l = t->get_locale(); -- cgit v1.2.3