[Git][NTPsec/ntpsec][master] Remove dead code for unused struct timeval operations.

Eric S. Raymond gitlab at mg.gitlab.com
Fri Sep 30 10:49:56 UTC 2016


Eric S. Raymond pushed to branch master at NTPsec / ntpsec


Commits:
b2ffb019 by Eric S. Raymond at 2016-09-30T06:49:11-04:00
Remove dead code for unused struct timeval operations.

- - - - -


2 changed files:

- include/timevalops.h
- tests/libntp/timevalops.c


Changes:

=====================================
include/timevalops.h
=====================================
--- a/include/timevalops.h
+++ b/include/timevalops.h
@@ -5,6 +5,8 @@
  *
  * For a rationale look at 'timespecops.h'; we do the same here, but the
  * normalisation keeps the microseconds in [0 .. 10^6], of course.
+ * NTPsec implements fewer operations here as we are trying to do as
+ * much arithmetic as possible in nanoseconds for code-hygiene reasons.
  *
  * Copyright 2015 by the NTPsec project contributors
  * SPDX-License-Identifier: NTP
@@ -86,12 +88,6 @@
 #define timeval_isnormal(x) \
 	((x)->tv_usec >= 0 && (x)->tv_usec < MICROSECONDS)
 
-/*
- * predicate: returns true if the microseconds are out-of-bounds
- * use like: int timeval_isdenormal(const struct timeval *x)
- */
-#define timeval_isdenormal(x)	(!timeval_isnormal(x))
-
 /* make sure microseconds are in nominal range */
 static inline struct timeval
 normalize_tval(
@@ -101,7 +97,7 @@ normalize_tval(
 	long		z;
 
 	/*
-	 * If the fraction becomes excessive denormal, we use division
+	 * If the fraction becomes excessively denormal, we use division
 	 * to do first partial normalisation. The normalisation loops
 	 * following will do the remaining cleanup. Since the size of
 	 * tv_usec has a peculiar definition by the standard the range
@@ -152,21 +148,6 @@ add_tval(
 	return normalize_tval(x);
 }
 
-/* x = a + b, b is fraction only */
-static inline struct timeval
-add_tval_us(
-	struct timeval	a,
-	long		b
-	)
-{
-	struct timeval x;
-
-	x = a;
-	x.tv_usec += b;
-
-	return normalize_tval(x);
-}
-
 /* x = a - b */
 static inline struct timeval
 sub_tval(
@@ -183,35 +164,6 @@ sub_tval(
 	return normalize_tval(x);
 }
 
-/* x = a - b, b is fraction only */
-static inline struct timeval
-sub_tval_us(
-	struct timeval	a,
-	long		b
-	)
-{
-	struct timeval x;
-
-	x = a;
-	x.tv_usec -= b;
-
-	return normalize_tval(x);
-}
-
-/* x = -a */
-static inline struct timeval
-neg_tval(
-	struct timeval	a
-	)
-{	
-	struct timeval	x;
-
-	x.tv_sec = -a.tv_sec;
-	x.tv_usec = -a.tv_usec;
-
-	return normalize_tval(x);
-}
-
 /* x = abs(a) */
 static inline struct timeval
 abs_tval(
@@ -284,27 +236,6 @@ test_tval(
 	return r;
 }
 
-/*
- * test possibly-denormal a
- * return 1 / 0 / -1 if a < / == / > 0
- */
-static inline int
-test_tval_denorm(
-	struct timeval	a
-	)
-{
-	return test_tval(normalize_tval(a));
-}
-
-/* return LIB buffer ptr to string rep */
-static inline const char *
-tvaltoa(
-	struct timeval	x
-	)
-{
-	return format_time_fraction(x.tv_sec, x.tv_usec, 6);
-}
-
 /* convert from timeval duration to l_fp duration */
 static inline l_fp
 tval_intv_to_lfp(
@@ -361,45 +292,4 @@ lfp_intv_to_tval(
 	return out;
 }
 
-static inline struct timeval
-lfp_uintv_to_tval(
-	l_fp		x
-	)
-{
-	struct timeval	out;
-	
-	TSFTOTVU(x.l_uf, out.tv_usec);
-	out.tv_sec = x.l_ui;
-
-	return out;
-}
-
-/*
- * absolute (timestamp) conversion. Input is time in NTP epoch, output
- * is in UN*X epoch. The NTP time stamp will be expanded around the
- * pivot time *p or the current time, if p is NULL.
- */
-static inline struct timeval
-lfp_stamp_to_tval(
-	l_fp		x,
-	const time_t *	p
-	)
-{
-	struct timeval	out;
-	vint64		sec;
-
-	sec = ntpcal_ntp_to_time(x.l_ui, p);
-	TSFTOTVU(x.l_uf, out.tv_usec);
-
-	/* copying a vint64 to a time_t needs some care... */
-#if SIZEOF_TIME_T <= 4
-	out.tv_sec = (time_t)vint64lo(sec);
-#else
-	out.tv_sec = (time_t)vint64s(sec);
-#endif
-	out = normalize_tval(out);
-
-	return out;
-}
-
 #endif	/* GUARD_TIMEVALOPS_H */


=====================================
tests/libntp/timevalops.c
=====================================
--- a/tests/libntp/timevalops.c
+++ b/tests/libntp/timevalops.c
@@ -314,36 +314,6 @@ TEST(timevalops, AddFullOflow1) {
 	return;
 }
 
-TEST(timevalops, AddUsecNorm) {
-	int i;
-
-	for (i = -4; i <= 4; ++i) {
-		struct timeval a = timeval_init(i, 200);
-		struct timeval E = timeval_init(i, 600);
-		struct timeval c;
-
-		c = add_tval_us(a, 600 - 200);
-		TEST_ASSERT_EQUAL_timeval(E, c);
-	}
-
-	return;
-}
-
-TEST(timevalops, AddUsecOflow1) {
-	int i;
-
-	for (i = -4; i <= 4; ++i) {
-		struct timeval a = timeval_init(i, 200);
-		struct timeval E = timeval_init(i + 1, 100);
-		struct timeval c;
-
-		c = add_tval_us(a, MICROSECONDS - 100);
-		TEST_ASSERT_EQUAL_timeval(E, c);
-	}
-
-	return;
-}
-
 //----------------------------------------------------------------------
 // test subtraction (difference)
 //----------------------------------------------------------------------
@@ -382,56 +352,6 @@ TEST(timevalops, SubFullOflow) {
 	return;
 }
 
-TEST(timevalops, SubUsecNorm) {
-	int i = -4;
-
-	for (i = -4; i <= 4; ++i) {
-		struct timeval a = timeval_init(i, 600);
-		struct timeval E = timeval_init(i, 200);
-		struct timeval c;
-
-		c = sub_tval_us(a, 600 - 200);
-		TEST_ASSERT_EQUAL_timeval(E, c);
-	}
-
-	return;
-}
-
-TEST(timevalops, SubUsecOflow) {
-	int i = -4;
-
-	for (i = -4; i <= 4; ++i) {
-		struct timeval a = timeval_init(i, 100);
-		struct timeval E = timeval_init(i - 1, 200);
-		struct timeval c;
-
-		c = sub_tval_us(a, MICROSECONDS - 100);
-		TEST_ASSERT_EQUAL_timeval(E, c);
-	}
-
-	return;
-}
-
-//----------------------------------------------------------------------
-// test negation
-//----------------------------------------------------------------------
-
-TEST(timevalops, Neg) {
-	int i = -4;
-
-	for (i = -4; i <= 4; ++i) {
-		struct timeval a = timeval_init(i, 100);
-		struct timeval b;
-		struct timeval c;
-
-		b = neg_tval(a);
-		c = add_tval(a, b);
-		TEST_ASSERT_EQUAL(0, test_tval(c));
-	}
-
-	return;
-}
-
 //----------------------------------------------------------------------
 // test abs value
 //----------------------------------------------------------------------
@@ -650,39 +570,6 @@ TEST(timevalops, LFProundtrip) {
 	return;
 }
 
-//----------------------------------------------------------------------
-// string formatting
-//----------------------------------------------------------------------
-
-TEST(timevalops, ToString) {
-	static const struct {
-		time_t	     sec;
-		long	     usec;
-		const char * repr;
-	} data [] = {
-		{ 0, 0,	 "0.000000" },
-		{ 2, 0,	 "2.000000" },
-		{-2, 0, "-2.000000" },
-		{ 0, 1,	 "0.000001" },
-		{ 0,-1,	"-0.000001" },
-		{ 1,-1,	 "0.999999" },
-		{-1, 1, "-0.999999" },
-		{-1,-1, "-1.000001" },
-	};
-	int i;
-
-	for (i = 0; i < (int)COUNTOF(data); ++i) {
-		struct timeval a = timeval_init(data[i].sec, data[i].usec);
-		const char *  E = data[i].repr;
-		const char *  r = tvaltoa(a);
-
-		TEST_ASSERT_EQUAL_STRING(E, r);
-	}
-
-	return;
-}
-
-
 TEST_GROUP_RUNNER(timevalops) {
 	RUN_TEST_CASE(timevalops, Helpers1);
 	RUN_TEST_CASE(timevalops, Normalise);
@@ -693,13 +580,8 @@ TEST_GROUP_RUNNER(timevalops) {
 	RUN_TEST_CASE(timevalops, CmpFracLT);
 	RUN_TEST_CASE(timevalops, AddFullNorm);
 	RUN_TEST_CASE(timevalops, AddFullOflow1);
-	RUN_TEST_CASE(timevalops, AddUsecNorm);
-	RUN_TEST_CASE(timevalops, AddUsecOflow1);
 	RUN_TEST_CASE(timevalops, SubFullNorm);
 	RUN_TEST_CASE(timevalops, SubFullOflow);
-	RUN_TEST_CASE(timevalops, SubUsecNorm);
-	RUN_TEST_CASE(timevalops, SubUsecOflow);
-	RUN_TEST_CASE(timevalops, Neg);
 	RUN_TEST_CASE(timevalops, AbsNoFrac);
 	RUN_TEST_CASE(timevalops, AbsWithFrac);
 	/* RUN_TEST_CASE(timevalops, Helpers2); */
@@ -711,7 +593,6 @@ TEST_GROUP_RUNNER(timevalops) {
 	RUN_TEST_CASE(timevalops, FromLFPrelPos);
 	RUN_TEST_CASE(timevalops, FromLFPrelNeg);
 	RUN_TEST_CASE(timevalops, LFProundtrip);
-	RUN_TEST_CASE(timevalops, ToString);
 }
 
 // -*- EOF -*-



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/b2ffb0196dda4e2bda4005989a99c900521ba43b
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20160930/9b813163/attachment.html>


More information about the vc mailing list