]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
Minor code improvement to timespec_subtract example
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Jun 2024 15:40:41 +0000 (08:40 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 15 Jun 2024 15:53:50 +0000 (08:53 -0700)
This saves a few instructions.
BORROW cannot be -1, since NSEC_DIFF is at most 999999999.
Idea taken from Gnulib, here:
https://git.savannah.gnu.org/cgit/gnulib.git/commit/?id=fe33f943054b93af8b965ce6564b8713b0979a21

manual/examples/timespec_subtract.c

index 380d173aabb5b30a30c94c17d3820b8960274f52..26607409c8386ede8ee786d9783b8d360b470ace 100644 (file)
 
 bool
 timespec_subtract (struct timespec *r,
-                  struct timespec x, struct timespec y)
+                   struct timespec x, struct timespec y)
 {
-  /* Compute nanoseconds, setting @var{borrow} to 1, 0, or -1
+  /* Compute nanoseconds, setting @var{borrow} to 1 or 0
      for propagation into seconds.  */
   long int nsec_diff = x.tv_nsec - y.tv_nsec;
-  int borrow = (nsec_diff < 0) - ! (nsec_diff < 1000000000);
+  bool borrow = nsec_diff < 0;
   r->tv_nsec = nsec_diff + 1000000000 * borrow;
 
   /* Compute seconds, returning true if this overflows.  */