Use a map instead of a vbector

This commit is contained in:
Flakebi 2015-08-16 22:24:07 +02:00
parent 8c09228b39
commit c07f806afb
2 changed files with 7 additions and 16 deletions

View File

@ -361,14 +361,6 @@ Translations::Translations() //: m_dictionary_manager("UTF-16")
Translations::~Translations()
{
// Remove cached strings
for (std::vector<std::pair<wchar_t*, wchar_t*> >::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<std::pair<wchar_t*, wchar_t*> >::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 irr::core::stringw, const irr::core::stringw>::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<wchar_t*, wchar_t*>(
m_fribidized_strings.insert(std::pair<const irr::core::stringw, const irr::core::stringw>(
original_string, fribidized_string));
return fribidized_string;

View File

@ -20,6 +20,7 @@
#define TRANSLATION_HPP
#include <irrString.h>
#include <map>
#include <string>
#include <utility>
#include <vector>
@ -49,7 +50,7 @@ private:
tinygettext::Dictionary m_dictionary;
/** A map that saves all fribidized strings: Original string, fribidized string */
std::vector<std::pair<wchar_t*, wchar_t*> > m_fribidized_strings;
std::map<const irr::core::stringw, const irr::core::stringw> m_fribidized_strings;
bool m_rtl;
std::string m_current_language_name;