]> Savannah Git Hosting - gnulib.git/commitdiff
gethrxtime: improve xtime_sec performance
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Dec 2019 03:04:50 +0000 (19:04 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Dec 2019 03:05:28 +0000 (19:05 -0800)
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
lib/xtime.h

index e0ecf87b78f7ebfd2d09916d85c9f180cde69c05..f6a705a7a23fa588e92b3457fb0827c4501217a9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2019-12-23  Paul Eggert  <eggert@cs.ucla.edu>
+
+       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  <bruno@clisp.org>
 
        setlocale-null: Export the lock function also on non-Windows platforms.
index 5dea46767194a757760940d4cca505e9468f022c..25185d01b02bba26402aaea53fd5968c5467c980 100644 (file)
@@ -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.  */