Avoid at least some unnecessary setlocale() calls

Instead of calling wxLanguageInfo::GetLocaleName(), which called
setlocale() at least thrice (first to query the current locale, second
to try to change it and third to restore the original locale) and then
calling setlocale() again if it succeeded, use the new TrySetLocale()
method which calls setlocale() just once and doesn't require calling it
again in the caller.

This makes the code slightly more efficient but, more importantly,
shorter and more clear.
This commit is contained in:
Vadim Zeitlin
2017-07-14 19:07:20 +02:00
parent 1003cf3e92
commit 8713d73466
2 changed files with 29 additions and 28 deletions

View File

@@ -75,6 +75,13 @@ struct WXDLLIMPEXP_BASE wxLanguageInfo
// setlocale() on the current system or empty string if this locale is not
// supported
wxString GetLocaleName() const;
// Call setlocale() and return non-null value if it works for this language.
//
// This function is mostly for internal use, as changing locale involves
// more than just calling setlocale() on some platforms, use wxLocale to
// do everything that needs to be done instead of calling this method.
const char* TrySetLocale() const;
};
// ----------------------------------------------------------------------------