diff options
author | Bruno Haible <bruno@clisp.org> | 2019-12-22 09:46:46 +0100 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2019-12-22 09:46:46 +0100 |
commit | 896daf273035e889c50dc5b33e74b5fb891851bc (patch) | |
tree | 5cfeb92f689315c1a3227e5fc54bcec66b2cf6e3 /lib/xtime.h | |
parent | 3a5d13f42ba42a4e1625bdbcdd93bd2099c550a0 (diff) | |
download | gnulib-896daf273035e889c50dc5b33e74b5fb891851bc.tar.gz |
gethrxtime: Assume that the compiler supports 'long long'.
* lib/xtime.h (xtime_t): Define to 'long long int' always.
(XTIME_PRECISION): Define to 1000000000 always.
(xtime_make, xtime_sec): Optimize accordingly.
* m4/gethrxtime.m4 (gl_XTIME): Don't require AC_TYPE_LONG_LONG_INT.
* modules/gethrxtime (Files): Remove longlong.m4.
Diffstat (limited to 'lib/xtime.h')
-rw-r--r-- | lib/xtime.h | 25 |
1 files changed, 4 insertions, 21 deletions
diff --git a/lib/xtime.h b/lib/xtime.h index 9edd12392d..77f1c30faa 100644 --- a/lib/xtime.h +++ b/lib/xtime.h @@ -29,21 +29,9 @@ _GL_INLINE_HEADER_BEGIN #endif /* xtime_t is a signed type used for timestamps. It is an integer - type that is a count of nanoseconds -- except for obsolescent hosts - without sufficiently-wide integers, where it is a count of - seconds. */ -#if HAVE_LONG_LONG_INT + type that is a count of nanoseconds. */ typedef long long int xtime_t; -# define XTIME_PRECISION 1000000000 -#else -# include <limits.h> -typedef long int xtime_t; -# if LONG_MAX >> 31 >> 31 == 0 -# define XTIME_PRECISION 1 -# else -# define XTIME_PRECISION 1000000000 -# endif -#endif +#define XTIME_PRECISION 1000000000 #ifdef __cplusplus extern "C" { @@ -57,10 +45,7 @@ xtime_make (xtime_t s, long int ns) const long int giga = 1000 * 1000 * 1000; s += ns / giga; ns %= giga; - if (XTIME_PRECISION == 1) - return s; - else - return XTIME_PRECISION * s + ns; + return XTIME_PRECISION * s + ns; } /* Return the number of seconds in T, which must be nonnegative. */ @@ -74,9 +59,7 @@ xtime_nonnegative_sec (xtime_t t) XTIME_INLINE xtime_t xtime_sec (xtime_t t) { - return (XTIME_PRECISION == 1 - ? t - : t < 0 + return (t < 0 ? (t + XTIME_PRECISION - 1) / XTIME_PRECISION - 1 : xtime_nonnegative_sec (t)); } |