summaryrefslogtreecommitdiff
path: root/libs/pbd/locale_guard.cc
diff options
context:
space:
mode:
authorBen Loftis <ben@harrisonconsoles.com>2015-01-18 09:43:05 -0600
committerBen Loftis <ben@harrisonconsoles.com>2015-01-18 09:43:21 -0600
commitd3227ac0d0f8e492580c726d8a862f4f745c88da (patch)
treed9f84c5c4e1ba07742981838811f2ec6236da301 /libs/pbd/locale_guard.cc
parent219a09496f890caaf1709ef3e4e868f3db29e7bb (diff)
Dramatically improve windows session-save-time by avoiding recursive calls to set_locale.
Diffstat (limited to 'libs/pbd/locale_guard.cc')
-rw-r--r--libs/pbd/locale_guard.cc29
1 files changed, 17 insertions, 12 deletions
diff --git a/libs/pbd/locale_guard.cc b/libs/pbd/locale_guard.cc
index 44b9fc2b64..b8493cf176 100644
--- a/libs/pbd/locale_guard.cc
+++ b/libs/pbd/locale_guard.cc
@@ -25,24 +25,29 @@
using namespace PBD;
+// try to avoid calling setlocale() recursively. this is not thread-safe.
+std::string PBD::LocaleGuard::current;
+
LocaleGuard::LocaleGuard (const char* str)
+ : old(0)
{
- old = setlocale (LC_NUMERIC, NULL);
-
- if (old) {
- old = strdup (old);
- if (strcmp (old, str)) {
- setlocale (LC_NUMERIC, str);
- }
- }
+ 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);
+ }
}
+