From f63697432e6214e4be3c38648d71ccffaa0c7545 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sat, 1 Sep 2018 02:03:24 +0000 Subject: merge revision(s) 63994: [Backport #14920] reduce tzset * time.c (rb_localtime_r): call tzset() only after TZ environment variable is changed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_5@64602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- time.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'time.c') diff --git a/time.c b/time.c index e0a95097bd..672a794efe 100644 --- a/time.c +++ b/time.c @@ -646,12 +646,18 @@ static struct vtm *localtimew(wideval_t timew, struct vtm *result); static int leap_year_p(long y); #define leap_year_v_p(y) leap_year_p(NUM2LONG(modv((y), INT2FIX(400)))) +int ruby_tz_update; + static struct tm * rb_localtime_r(const time_t *t, struct tm *result) { #if defined __APPLE__ && defined __LP64__ if (*t != (time_t)(int)*t) return NULL; #endif + if (!ruby_tz_update) { + ruby_tz_update = 1; + tzset(); + } #ifdef HAVE_GMTIME_R result = localtime_r(t, result); #else @@ -677,7 +683,7 @@ rb_localtime_r(const time_t *t, struct tm *result) #endif return result; } -#define LOCALTIME(tm, result) (tzset(),rb_localtime_r((tm), &(result))) +#define LOCALTIME(tm, result) rb_localtime_r((tm), &(result)) #ifndef HAVE_STRUCT_TM_TM_GMTOFF static struct tm * -- cgit v1.2.3