[前][次][番号順一覧][スレッド一覧]

ruby-changes:59694

From: John <ko1@a...>
Date: Tue, 14 Jan 2020 06:58:49 +0900 (JST)
Subject: [ruby-changes:59694] c2e45422f7 (master): Store "UTC" and "" fstring as globals in time.c

https://git.ruby-lang.org/ruby.git/commit/?id=c2e45422f7

From c2e45422f7abc9836d3b68bb94e527b3aad9bfd7 Mon Sep 17 00:00:00 2001
From: John Hawthorn <john@h...>
Date: Thu, 2 Jan 2020 11:48:02 -0800
Subject: Store "UTC" and "" fstring as globals in time.c


diff --git a/time.c b/time.c
index 0f7b35f..fbccc90 100644
--- a/time.c
+++ b/time.c
@@ -47,6 +47,8 @@ static ID id_submicro, id_nano_num, id_nano_den, id_offset, id_zone; https://github.com/ruby/ruby/blob/trunk/time.c#L47
 static ID id_nanosecond, id_microsecond, id_millisecond, id_nsec, id_usec;
 static ID id_local_to_utc, id_utc_to_local, id_find_timezone;
 static ID id_year, id_mon, id_mday, id_hour, id_min, id_sec, id_isdst;
+static VALUE str_utc, str_empty;
+
 #define id_quo idQuo
 #define id_div idDiv
 #define id_divmod idDivmod
@@ -1023,7 +1025,7 @@ gmtimew_noleapsecond(wideval_t timew, struct vtm *vtm) https://github.com/ruby/ruby/blob/trunk/time.c#L1025
     }
 
     vtm->utc_offset = INT2FIX(0);
-    vtm->zone = rb_fstring_lit("UTC");
+    vtm->zone = str_utc;
 }
 
 static struct tm *
@@ -1455,7 +1457,7 @@ guess_local_offset(struct vtm *vtm_utc, int *isdst_ret, VALUE *zone_ret) https://github.com/ruby/ruby/blob/trunk/time.c#L1457
 
     timev = w2v(rb_time_unmagnify(timegmw(&vtm2)));
     t = NUM2TIMET(timev);
-    zone = rb_fstring_lit("UTC");
+    zone = str_utc;
     if (localtime_with_gmtoff_zone(&t, &tm, &gmtoff, &zone)) {
         if (isdst_ret)
             *isdst_ret = tm.tm_isdst;
@@ -2299,7 +2301,7 @@ time_init_1(int argc, VALUE *argv, VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L2301
 
     vtm.wday = VTM_WDAY_INITVAL;
     vtm.yday = 0;
-    vtm.zone = rb_fstring_lit("");
+    vtm.zone = str_empty;
 
     /*                             year  mon   mday  hour  min   sec   off */
     rb_scan_args(argc, argv, "16", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5],&v[6]);
@@ -2994,7 +2996,7 @@ time_arg(int argc, const VALUE *argv, struct vtm *vtm) https://github.com/ruby/ruby/blob/trunk/time.c#L2996
     vtm->wday = 0;
     vtm->yday = 0;
     vtm->isdst = 0;
-    vtm->zone = rb_fstring_lit("");
+    vtm->zone = str_empty;
 
     if (argc == 10) {
 	v[0] = argv[5];
@@ -3918,7 +3920,7 @@ time_gmtime(VALUE time) https://github.com/ruby/ruby/blob/trunk/time.c#L3920
 	time_modify(time);
     }
 
-    vtm.zone = rb_fstring_lit("UTC");
+    vtm.zone = str_utc;
     GMTIMEW(tobj->timew, &vtm);
     tobj->vtm = vtm;
 
@@ -5367,7 +5369,7 @@ time_mload(VALUE time, VALUE str) https://github.com/ruby/ruby/blob/trunk/time.c#L5369
         vtm.utc_offset = INT2FIX(0);
 	vtm.yday = vtm.wday = 0;
 	vtm.isdst = 0;
-	vtm.zone = rb_fstring_lit("");
+	vtm.zone = str_empty;
 
 	usec = (long)(s & 0xfffff);
         nsec = usec * 1000;
@@ -5841,6 +5843,11 @@ Init_Time(void) https://github.com/ruby/ruby/blob/trunk/time.c#L5843
     id_isdst = rb_intern("isdst");
     id_find_timezone = rb_intern("find_timezone");
 
+    str_utc = rb_fstring_lit("UTC");
+    rb_gc_register_mark_object(str_utc);
+    str_empty = rb_fstring_lit("");
+    rb_gc_register_mark_object(str_empty);
+
     rb_cTime = rb_define_class("Time", rb_cObject);
     rb_include_module(rb_cTime, rb_mComparable);
 
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]