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:
@@ -161,9 +161,10 @@ int wxGetTimeZone()
|
|||||||
ftime(&tb);
|
ftime(&tb);
|
||||||
return tb.timezone*60;
|
return tb.timezone*60;
|
||||||
#elif defined(__VISUALC__)
|
#elif defined(__VISUALC__)
|
||||||
// We must initialize the time zone information before using it (this will
|
// We must initialize the time zone information before using it. It's not a
|
||||||
// be done only once internally).
|
// problem if we do it twice due to a race condition, as it's idempotent
|
||||||
_tzset();
|
// 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
|
// Starting with VC++ 8 timezone variable is deprecated and is not even
|
||||||
// available in some standard library version so use the new function for
|
// available in some standard library version so use the new function for
|
||||||
@@ -177,7 +178,7 @@ int wxGetTimeZone()
|
|||||||
#endif
|
#endif
|
||||||
#else // Use some kind of time zone variable.
|
#else // Use some kind of time zone variable.
|
||||||
// In any case we must initialize the time zone before using it.
|
// 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.
|
#if defined(WX_TIMEZONE) // If WX_TIMEZONE was defined by configure, use it.
|
||||||
return WX_TIMEZONE;
|
return WX_TIMEZONE;
|
||||||
|
Reference in New Issue
Block a user