mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
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
This commit is contained in:
parent
ee768a30fe
commit
7c1ec1b7d0
@ -24,10 +24,10 @@ bool
|
|||||||
timespec_subtract (struct timespec *r,
|
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. */
|
for propagation into seconds. */
|
||||||
long int nsec_diff = x.tv_nsec - y.tv_nsec;
|
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;
|
r->tv_nsec = nsec_diff + 1000000000 * borrow;
|
||||||
|
|
||||||
/* Compute seconds, returning true if this overflows. */
|
/* Compute seconds, returning true if this overflows. */
|
||||||
|
Loading…
Reference in New Issue
Block a user