aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-17 10:48:17 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-12-17 10:48:17 +0900
commitebe5b66ca8e639468e14c4134a415403d949385e (patch)
tree22729f76fefe18fc1690e8921de11f14a787a477
parentd6a2bce64a7fa1099e507e1d36b5f1533f42f60f (diff)
downloadruby-ebe5b66ca8e639468e14c4134a415403d949385e.tar.gz
Reduce tzset calls
Set up-to-date flag always when calling tzset().
-rw-r--r--time.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/time.c b/time.c
index ef8a995da4..021421cdbf 100644
--- a/time.c
+++ b/time.c
@@ -673,16 +673,21 @@ static VALUE tm_from_time(VALUE klass, VALUE time);
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 *
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_uptodate_p) {
- ruby_tz_uptodate_p = true;
- tzset();
- }
+ update_tz();
#ifdef HAVE_GMTIME_R
result = localtime_r(t, result);
#else
@@ -3140,9 +3145,7 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp)
find_dst = 0 < tptr->tm_isdst;
/* /etc/localtime might be changed. reload it. */
- if (!ruby_tz_uptodate_p) {
- tzset();
- }
+ update_tz();
tm0 = *tptr;
if (tm0.tm_mon < 0) {