From: Paul Eggert Date: Tue, 24 Dec 2019 03:04:50 +0000 (-0800) Subject: gethrxtime: improve xtime_sec performance X-Git-Tag: v1.0~4430 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=6ad341ee4a0cca1a8b1744bc269282aafd765868;p=gnulib.git 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. --- diff --git a/ChangeLog b/ChangeLog index e0ecf87b78..f6a705a7a2 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 5dea467671..25185d01b0 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. */