Reduce tzset calls
Set up-to-date flag always when calling tzset().
This commit is contained in:
parent
d6a2bce64a
commit
ebe5b66ca8
17
time.c
17
time.c
@ -673,16 +673,21 @@ static VALUE tm_from_time(VALUE klass, VALUE time);
|
|||||||
|
|
||||||
bool ruby_tz_uptodate_p;
|
bool ruby_tz_uptodate_p;
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_tz(void)
|
||||||
|
{
|
||||||
|
if (ruby_tz_uptodate_p) return;
|
||||||
|
ruby_tz_uptodate_p = true;
|
||||||
|
tzset();
|
||||||
|
}
|
||||||
|
|
||||||
static struct tm *
|
static struct tm *
|
||||||
rb_localtime_r(const time_t *t, struct tm *result)
|
rb_localtime_r(const time_t *t, struct tm *result)
|
||||||
{
|
{
|
||||||
#if defined __APPLE__ && defined __LP64__
|
#if defined __APPLE__ && defined __LP64__
|
||||||
if (*t != (time_t)(int)*t) return NULL;
|
if (*t != (time_t)(int)*t) return NULL;
|
||||||
#endif
|
#endif
|
||||||
if (!ruby_tz_uptodate_p) {
|
update_tz();
|
||||||
ruby_tz_uptodate_p = true;
|
|
||||||
tzset();
|
|
||||||
}
|
|
||||||
#ifdef HAVE_GMTIME_R
|
#ifdef HAVE_GMTIME_R
|
||||||
result = localtime_r(t, result);
|
result = localtime_r(t, result);
|
||||||
#else
|
#else
|
||||||
@ -3140,9 +3145,7 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp)
|
|||||||
find_dst = 0 < tptr->tm_isdst;
|
find_dst = 0 < tptr->tm_isdst;
|
||||||
|
|
||||||
/* /etc/localtime might be changed. reload it. */
|
/* /etc/localtime might be changed. reload it. */
|
||||||
if (!ruby_tz_uptodate_p) {
|
update_tz();
|
||||||
tzset();
|
|
||||||
}
|
|
||||||
|
|
||||||
tm0 = *tptr;
|
tm0 = *tptr;
|
||||||
if (tm0.tm_mon < 0) {
|
if (tm0.tm_mon < 0) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user