about summary refs log tree commit diff
path: root/time/mktime.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2020-08-04 23:15:31 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2020-08-04 23:15:31 -0700
commitdb10cd9e62a29d6dccf55bbce367dab5a72220bb (patch)
treee8a0a591e2c85c3a0bd9f2f3558fc056319eacd3 /time/mktime.c
parent7279f0a282283db04352e247c3bdb39ee03d10f6 (diff)
downloadglibc-db10cd9e62a29d6dccf55bbce367dab5a72220bb.tar.gz
glibc-db10cd9e62a29d6dccf55bbce367dab5a72220bb.tar.xz
glibc-db10cd9e62a29d6dccf55bbce367dab5a72220bb.zip
Sync mktime.c from Gnulib
* time/mktime.c: Sync from Gnulib.
This micro-optimizes three division-related computations.
Diffstat (limited to 'time/mktime.c')
-rw-r--r--time/mktime.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/time/mktime.c b/time/mktime.c
index 63c82fc6a9..c8735164f6 100644
--- a/time/mktime.c
+++ b/time/mktime.c
@@ -141,7 +141,7 @@ shr (long_int a, int b)
   long_int one = 1;
   return (-one >> 1 == -1
 	  ? a >> b
-	  : a / (one << b) - (a % (one << b) < 0));
+	  : (a + (a < 0)) / (one << b) - (a < 0));
 }
 
 /* Bounds for the intersection of __time64_t and long_int.  */
@@ -211,8 +211,8 @@ ydhms_diff (long_int year1, long_int yday1, int hour1, int min1, int sec1,
      Take care to avoid integer overflow here.  */
   int a4 = shr (year1, 2) + shr (TM_YEAR_BASE, 2) - ! (year1 & 3);
   int b4 = shr (year0, 2) + shr (TM_YEAR_BASE, 2) - ! (year0 & 3);
-  int a100 = a4 / 25 - (a4 % 25 < 0);
-  int b100 = b4 / 25 - (b4 % 25 < 0);
+  int a100 = (a4 + (a4 < 0)) / 25 - (a4 < 0);
+  int b100 = (b4 + (b4 < 0)) / 25 - (b4 < 0);
   int a400 = shr (a100, 2);
   int b400 = shr (b100, 2);
   int intervening_leap_days = (a4 - b4) - (a100 - b100) + (a400 - b400);