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

ruby-changes:66610

From: Nobuyoshi <ko1@a...>
Date: Sun, 27 Jun 2021 08:54:06 +0900 (JST)
Subject: [ruby-changes:66610] bf789af28a (master): Added macros for days in month

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

From bf789af28a3b7108186743f3cb4fd2f649afdd20 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Sat, 26 Jun 2021 22:52:30 +0900
Subject: Added macros for days in month

---
 time.c | 21 ++++++++-------------
 1 file changed, 8 insertions(+), 13 deletions(-)

diff --git a/time.c b/time.c
index a8782ac..9f5e4d3 100644
--- a/time.c
+++ b/time.c
@@ -783,6 +783,9 @@ static const int8_t leap_year_days_in_month[] = { https://github.com/ruby/ruby/blob/trunk/time.c#L783
     31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
 };
 
+#define days_in_month_of(leap) ((leap) ? leap_year_days_in_month : common_year_days_in_month)
+#define days_in_month_in(y) days_in_month_of(leap_year_p(y))
+
 #define M28(m) \
     (m),(m),(m),(m),(m),(m),(m),(m),(m),(m), \
     (m),(m),(m),(m),(m),(m),(m),(m),(m),(m), \
@@ -1107,9 +1110,7 @@ gmtime_with_leapsecond(const time_t *timep, struct tm *result) https://github.com/ruby/ruby/blob/trunk/time.c#L1110
                 result->tm_yday = leap_year_p(result->tm_year + 1900) ? 365 : 364;
             }
             else if (result->tm_mday == 1) {
-                const int8_t *days_in_month = leap_year_p(result->tm_year + 1900) ?
-                                           leap_year_days_in_month :
-                                           common_year_days_in_month;
+                const int8_t *days_in_month = days_in_month_of(result->tm_year + 1900);
                 result->tm_mon--;
                 result->tm_mday = days_in_month[result->tm_mon];
                 result->tm_yday--;
@@ -1128,8 +1129,7 @@ gmtime_with_leapsecond(const time_t *timep, struct tm *result) https://github.com/ruby/ruby/blob/trunk/time.c#L1129
                 result->tm_mday = 1;
                 result->tm_yday = 0;
             }
-            else if (result->tm_mday == (leap ? leap_year_days_in_month :
-                                                common_year_days_in_month)[result->tm_mon]) {
+            else if (result->tm_mday == days_in_month_of(leap)[result->tm_mon]) {
                 result->tm_mon++;
                 result->tm_mday = 1;
                 result->tm_yday++;
@@ -2030,9 +2030,7 @@ vtm_add_offset(struct vtm *vtm, VALUE off, int sign) https://github.com/ruby/ruby/blob/trunk/time.c#L2030
                 vtm->yday = leap_year_v_p(vtm->year) ? 366 : 365;
             }
             else if (vtm->mday == 1) {
-                const int8_t *days_in_month = leap_year_v_p(vtm->year) ?
-                                           leap_year_days_in_month :
-                                           common_year_days_in_month;
+                const int8_t *days_in_month = days_in_month_in(vtm->year);
                 vtm->mon--;
                 vtm->mday = days_in_month[vtm->mon-1];
                 vtm->yday--;
@@ -2051,8 +2049,7 @@ vtm_add_offset(struct vtm *vtm, VALUE off, int sign) https://github.com/ruby/ruby/blob/trunk/time.c#L2049
                 vtm->mday = 1;
                 vtm->yday = 1;
             }
-            else if (vtm->mday == (leap ? leap_year_days_in_month :
-                                          common_year_days_in_month)[vtm->mon-1]) {
+            else if (vtm->mday == days_in_month_of(leap)[vtm->mon-1]) {
                 vtm->mon++;
                 vtm->mday = 1;
                 vtm->yday++;
@@ -3061,9 +3058,7 @@ find_time_t(struct tm *tptr, int utc_p, time_t *tp) https://github.com/ruby/ruby/blob/trunk/time.c#L3058
 	tm0.tm_min = 0;
 	tm0.tm_sec = 0;
     }
-    else if ((d = (leap_year_p(1900 + tm0.tm_year) ?
-                   leap_year_days_in_month :
-		   common_year_days_in_month)[tm0.tm_mon]) < tm0.tm_mday) {
+    else if ((d = days_in_month_in(1900 + tm0.tm_year)[tm0.tm_mon]) < tm0.tm_mday) {
 	tm0.tm_mday = d;
 	tm0.tm_hour = 23;
 	tm0.tm_min = 59;
-- 
cgit v1.1


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

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