public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc] Minor code improvement to timespec_subtract example
@ 2024-06-15 16:14 Paul Eggert
  0 siblings, 0 replies; only message in thread
From: Paul Eggert @ 2024-06-15 16:14 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=7c1ec1b7d0b476610c811b0babeab831e626c088

commit 7c1ec1b7d0b476610c811b0babeab831e626c088
Author: Paul Eggert <eggert@cs.ucla.edu>
Date:   Sat Jun 15 08:40:41 2024 -0700

    Minor code improvement to timespec_subtract example
    
    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

Diff:
---
 manual/examples/timespec_subtract.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/manual/examples/timespec_subtract.c b/manual/examples/timespec_subtract.c
index 380d173aab..26607409c8 100644
--- a/manual/examples/timespec_subtract.c
+++ b/manual/examples/timespec_subtract.c
@@ -22,12 +22,12 @@
 
 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.  */

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-15 16:14 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-15 16:14 [glibc] Minor code improvement to timespec_subtract example Paul Eggert

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).