>From b91d291aecf2b8513a4b7a036f230c729f7867f2 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Thu, 14 Jan 2016 17:43:36 -0800
Subject: [PATCH 3/3] Remove quick_timegm and friends

* testsuite.c (quick_timegm, nleapsbetween):
Remove; not needed to test.  All uses removed.  This simplifies
the code and avoids some possible sources of overflow bugs.
---
 testsuite.c | 62 +++----------------------------------------------------------
 1 file changed, 3 insertions(+), 59 deletions(-)

diff --git a/testsuite.c b/testsuite.c
index d9188cf..f8b8903 100644
--- a/testsuite.c
+++ b/testsuite.c
@@ -194,9 +194,7 @@ static int getargs(char **, char *, int);
 static void runtests(FILE *, char const *);
 static void run_exhaustive(struct tm const *, struct tm const *, time_t);
 
-static time_t quick_timegm(struct tm const *);
 static int isleap(int) ATTRIBUTE_CONST;
-static int nleapsbetween(int, int) ATTRIBUTE_CONST;
 
 static int tmcmp(struct tm const *, struct tm const *) ATTRIBUTE_PURE;
 
@@ -429,15 +427,7 @@ basictest(time_t t, struct tm const *itmp, int flags, char const *tag)
 		tm.tm_wday = 0;
 		tm.tm_yday = 0;
 
-		if (flags & LOCAL) {
-			t2 = mktime(&tm);
-		} else {
-#ifdef TEST_QUICK_TIMEGM
-			t2 = quick_timegm(&tm);
-#else
-			t2 = timegm(&tm);
-#endif
-		}
+		t2 = (flags & LOCAL ? mktime : timegm)(&tm);
 
 		if (t2 != t) {
 			printf("%s: inverse expected %ld, got %ld\n",
@@ -589,7 +579,8 @@ run_exhaustive(struct tm const *from, struct tm const *to, time_t inc)
 	       to->tm_year+1900, to->tm_mon+1, to->tm_mday, inc);
 
 	tm = *from;
-	t = quick_timegm(from);
+	t = timegm(&tm);
+	tm = *from;
 
 	tm.tm_wday = (t / 86400 + EPOCH_WDAY) % 7;
 	if (tm.tm_wday < 0) tm.tm_wday += 7;
@@ -752,59 +743,12 @@ tmcmp(struct tm const *tm1, struct tm const *tm2)
 	else return 0;
 }
 
-static time_t
-quick_timegm(struct tm const *tmp)
-{
-	int m;
-	time_t r = (time_t)(1900 + tmp->tm_year - 1970) * 365 * 86400;
-	r += nleapsbetween(1970, 1900 + tmp->tm_year-1) * (time_t) 86400;
-#ifdef DEBUG
-	printf("quick_timegm: nleapsbetween: %d\n",
-	       nleapsbetween(1970, 1900 + tmp->tm_year-1));
-#endif
-	for (m = 0; m < tmp->tm_mon; m++)
-		r += monthlens[isleap(1900+tmp->tm_year)][m] * 86400;
-	r += (tmp->tm_mday - 1) * 86400;
-	r += (tmp->tm_hour * 60 + tmp->tm_min) * 60 + tmp->tm_sec;
-#ifdef DEBUG
-	printf("quick_timegm: %04d-%02d-%02d %02d:%02d:%02d -> %ld\n",
-	       1900+tmp->tm_year, tmp->tm_mon+1, tmp->tm_mday,
-	       tmp->tm_hour, tmp->tm_min, tmp->tm_sec, r);
-#endif
-	return r;
-}
-
 static int
 isleap(int y)
 {
 	return y % 4 == 0 && (y % 100 != 0 || y % 400 == 0);
 }
 
-static int
-nleapsbetween(int y1, int y2)
-{
-	if (y1 == y2) {
-		return 0;	/* unnecessary optimization */
-	} else if (y1 != 0) {
-		return nleapsbetween(0, y2) - nleapsbetween(0, y1);
-	} else {
-		/*
-		 *  This could simply be
-		 *	return y2 / 4 - y2 / 100 + y2 / 400;
-		 *  if only C guaranteed Euclidean division...
-		 */
-		int ret = 0;
-		int q = y2 / 4;
-		if (y2 % 4 < 0) q--;
-		ret += q;
-		q = y2 / 100; if (y2 % 100 < 0) q--;
-		ret -= q;
-		q = y2 / 400; if (y2 % 400 < 0) q--;
-		ret += q;
-		return ret;
-	}
-}
-
 static void
 catchsig(int sig)
 {
-- 
2.5.0

