diff --git a/src/utils/translation.cpp b/src/utils/translation.cpp index 151ce9f2b..87d95edae 100644 --- a/src/utils/translation.cpp +++ b/src/utils/translation.cpp @@ -361,14 +361,6 @@ Translations::Translations() //: m_dictionary_manager("UTF-16") Translations::~Translations() { - // Remove cached strings - for (std::vector >::iterator it = - m_fribidized_strings.begin(); it != m_fribidized_strings.end(); it++) - { - delete[] it->first; - delete[] it->second; - } - m_fribidized_strings.clear(); } // ~Translations // ---------------------------------------------------------------------------- @@ -379,12 +371,10 @@ const wchar_t* Translations::fribidize(const wchar_t* in_ptr) if(this->isRTLLanguage()) { // Test if this string was already fribidized - for (std::vector >::iterator it = - m_fribidized_strings.begin(); it != m_fribidized_strings.end(); it++) - { - if (wcscmp(it->first, in_ptr) == 0) - return it->second; - } + std::map::const_iterator + found = m_fribidized_strings.find(in_ptr); + if (found != m_fribidized_strings.cend()) + return found->second.c_str(); // Use fribidi to fribidize the string FriBidiChar *fribidiInput = toFribidiChar(in_ptr); @@ -434,7 +424,7 @@ const wchar_t* Translations::fribidize(const wchar_t* in_ptr) std::wmemcpy(original_string, in_ptr, original_length); // Save it in the map - m_fribidized_strings.push_back(std::pair( + m_fribidized_strings.insert(std::pair( original_string, fribidized_string)); return fribidized_string; diff --git a/src/utils/translation.hpp b/src/utils/translation.hpp index 207418967..39e442864 100644 --- a/src/utils/translation.hpp +++ b/src/utils/translation.hpp @@ -20,6 +20,7 @@ #define TRANSLATION_HPP #include +#include #include #include #include @@ -49,7 +50,7 @@ private: tinygettext::Dictionary m_dictionary; /** A map that saves all fribidized strings: Original string, fribidized string */ - std::vector > m_fribidized_strings; + std::map m_fribidized_strings; bool m_rtl; std::string m_current_language_name;