>From 6ad341ee4a0cca1a8b1744bc269282aafd765868 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Dec 2019 19:04:50 -0800 Subject: [PATCH 1/4] gethrxtime: improve xtime_sec performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Performanced analyzed by Bruno Haible in: https://lists.gnu.org/r/bug-gnulib/2019-12/msg00200.html * lib/xtime.h (xtime_sec): Redo with neither ‘%’ nor conditional branches. --- ChangeLog | 8 ++++++++ lib/xtime.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e0ecf87b7..f6a705a7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-12-23 Paul Eggert + + gethrxtime: improve xtime_sec performance + Performanced analyzed by Bruno Haible in: + https://lists.gnu.org/r/bug-gnulib/2019-12/msg00200.html + * lib/xtime.h (xtime_sec): Redo with neither ‘%’ nor conditional + branches. + 2019-12-23 Bruno Haible setlocale-null: Export the lock function also on non-Windows platforms. diff --git a/lib/xtime.h b/lib/xtime.h index 5dea46767..25185d01b 100644 --- a/lib/xtime.h +++ b/lib/xtime.h @@ -61,7 +61,7 @@ xtime_nonnegative_sec (xtime_t t) XTIME_INLINE xtime_t xtime_sec (xtime_t t) { - return t / XTIME_PRECISION - (t % XTIME_PRECISION < 0); + return (t + (t < 0)) / XTIME_PRECISION - (t < 0); } /* Return the number of nanoseconds in T, which must be nonnegative. */ -- 2.17.1