aboutsummaryrefslogtreecommitdiffstats
path: root/time.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2019-11-13 16:53:12 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2019-11-13 16:54:31 +0900
commite7ea6e078fecb70fbc91b04878b69f696749afac (patch)
tree58598628977fb8c4117977de6f19a73e82835579 /time.c
parent3324bc9d172e52114add3a0cdd426b5648cdc33b (diff)
downloadruby-e7ea6e078fecb70fbc91b04878b69f696749afac.tar.gz
Check more likely condition first [Feature #16335]
Diffstat (limited to 'time.c')
-rw-r--r--time.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/time.c b/time.c
index a7a95b6b86..8a573c0d67 100644
--- a/time.c
+++ b/time.c
@@ -3067,7 +3067,16 @@ time_arg(int argc, const VALUE *argv, struct vtm *vtm)
static int
leap_year_p(long y)
{
- return ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0);
+ /* TODO:
+ * ensure about negative years in proleptic Gregorian calendar.
+ */
+ unsigned long uy = (unsigned long)(LIKELY(y >= 0) ? y : -y);
+
+ if (LIKELY(uy % 4 != 0)) return 0;
+
+ unsigned long century = uy / 100;
+ if (LIKELY(uy != century * 100)) return 1;
+ return century % 4 == 0;
}
static time_t