Only call tzset() once and not from each wxGetTimeZone() call

Doing this resulted in noticeable performance problems under MSW,
especially when using non-default locale.

Closes #17094.
This commit is contained in:
Vadim Zeitlin 2019-09-26 01:30:04 +02:00
parent 1753ed4037
commit 6789e69e4b

View File

@ -161,9 +161,10 @@ int wxGetTimeZone()
ftime(&tb);
return tb.timezone*60;
#elif defined(__VISUALC__)
// We must initialize the time zone information before using it (this will
// be done only once internally).
_tzset();
// We must initialize the time zone information before using it. It's not a
// problem if we do it twice due to a race condition, as it's idempotent
// anyhow, so don't bother with any locks here.
static bool s_tzSet = (_tzset(), true);
// Starting with VC++ 8 timezone variable is deprecated and is not even
// available in some standard library version so use the new function for
@ -177,7 +178,7 @@ int wxGetTimeZone()
#endif
#else // Use some kind of time zone variable.
// In any case we must initialize the time zone before using it.
tzset();
static bool s_tzSet = (tzset(), true);
#if defined(WX_TIMEZONE) // If WX_TIMEZONE was defined by configure, use it.
return WX_TIMEZONE;