Dramatically improve windows session-save-time by avoiding recursive calls to set_locale.
This commit is contained in:
parent
219a09496f
commit
d3227ac0d0
|
@ -25,24 +25,29 @@
|
|||
|
||||
using namespace PBD;
|
||||
|
||||
LocaleGuard::LocaleGuard (const char* str)
|
||||
{
|
||||
old = setlocale (LC_NUMERIC, NULL);
|
||||
// try to avoid calling setlocale() recursively. this is not thread-safe.
|
||||
std::string PBD::LocaleGuard::current;
|
||||
|
||||
if (old) {
|
||||
old = strdup (old);
|
||||
if (strcmp (old, str)) {
|
||||
setlocale (LC_NUMERIC, str);
|
||||
}
|
||||
}
|
||||
LocaleGuard::LocaleGuard (const char* str)
|
||||
: old(0)
|
||||
{
|
||||
if (current != str) {
|
||||
old = strdup (setlocale (LC_NUMERIC, NULL));
|
||||
if (strcmp (old, str)) {
|
||||
if (setlocale (LC_NUMERIC, str))
|
||||
current = str;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
LocaleGuard::~LocaleGuard ()
|
||||
{
|
||||
setlocale (LC_NUMERIC, old);
|
||||
if (old) {
|
||||
if (setlocale (LC_NUMERIC, old))
|
||||
current = old;
|
||||
|
||||
if (old) {
|
||||
free (const_cast<char*>(old));
|
||||
}
|
||||
free ((char*)old);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -22,12 +22,16 @@
|
|||
|
||||
#include "pbd/libpbd_visibility.h"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace PBD {
|
||||
|
||||
struct LIBPBD_API LocaleGuard {
|
||||
LocaleGuard (const char*);
|
||||
~LocaleGuard ();
|
||||
const char* old;
|
||||
|
||||
static std::string current;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user