Make _() and friends safe to call from any thread.
The GetUntranslatedString() hack keeps a global copy of all strings, so that it can return a const reference as wxGetTranslation() return value. A global wxHashSet instance shared by all threads won't do, even guarded with a critical section, because it may internally copy values on any insert and thus invalidate pointers that may still be used on another thread. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74833 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/fontmap.h"
|
||||
#include "wx/stdpaths.h"
|
||||
#include "wx/hashset.h"
|
||||
#include "wx/private/threadinfo.h"
|
||||
|
||||
#ifdef __WINDOWS__
|
||||
#include "wx/dynlib.h"
|
||||
@@ -1605,20 +1605,14 @@ wxString wxTranslations::GetBestTranslation(const wxString& domain,
|
||||
}
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
WX_DECLARE_HASH_SET(wxString, wxStringHash, wxStringEqual,
|
||||
wxLocaleUntranslatedStrings);
|
||||
}
|
||||
|
||||
/* static */
|
||||
const wxString& wxTranslations::GetUntranslatedString(const wxString& str)
|
||||
{
|
||||
static wxLocaleUntranslatedStrings s_strings;
|
||||
wxLocaleUntranslatedStrings& strings = wxThreadInfo.untranslatedStrings;
|
||||
|
||||
wxLocaleUntranslatedStrings::iterator i = s_strings.find(str);
|
||||
if ( i == s_strings.end() )
|
||||
return *s_strings.insert(str).first;
|
||||
wxLocaleUntranslatedStrings::iterator i = strings.find(str);
|
||||
if ( i == strings.end() )
|
||||
return *strings.insert(str).first;
|
||||
|
||||
return *i;
|
||||
}
|
||||
|
Reference in New Issue
Block a user