]> Savannah Git Hosting - gnulib.git/commitdiff
strptime: tweak division performance
authorPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Dec 2019 07:53:23 +0000 (23:53 -0800)
committerPaul Eggert <eggert@cs.ucla.edu>
Tue, 24 Dec 2019 07:55:13 +0000 (23:55 -0800)
* lib/strptime.c (day_of_the_week):
Redo with neither ‘%’ nor conditional branches.

ChangeLog
lib/strptime.c

index 4b471420400b80c34764ee136deacce7d5c38fb6..168037ed11291c77187d6d657aede452625467b4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,20 +1,15 @@
 2019-12-23  Paul Eggert  <eggert@cs.ucla.edu>
 
-       nstrftime: tweak division performance
-       * lib/nstrftime.c (SHR, tm_diff, __strftime_internal):
-       Redo with neither ‘%’ nor conditional branches.
-
-       mktime: tweak division performance
+       gethrxtime, mktime, nstrftime, strptime: tweak division performance
+       Performanced analyzed by Bruno Haible in:
+       https://lists.gnu.org/r/bug-gnulib/2019-12/msg00200.html
        * config/srclist.txt: Do not sync mktime.c for now.
        * lib/mktime.c (shr, ydhms_diff):
+       * lib/nstrftime.c (SHR, tm_diff, __strftime_internal):
+       * lib/strptime.c (day_of_the_week):
+       * lib/xtime.h (xtime_sec):
        Redo with neither ‘%’ nor conditional branches.
 
-       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 e6d405a442d0fff173d1e19725962e13192a2cb9..9c2c2e38b1aeba98e4b7d0b9dc14b4bf4bef74c7 100644 (file)
@@ -202,11 +202,12 @@ day_of_the_week (struct tm *tm)
      difference between this data in the one on TM and so determine
      the weekday.  */
   int corr_year = 1900 + tm->tm_year - (tm->tm_mon < 2);
+  int corr_quad = corr_year / 4;
   int wday = (-473
               + (365 * (tm->tm_year - 70))
-              + (corr_year / 4)
-              - ((corr_year / 4) / 25) + ((corr_year / 4) % 25 < 0)
-              + (((corr_year / 4) / 25) / 4)
+              + corr_quad
+              - (corr_quad + (corr_quad < 0)) / 25 - (corr_quad < 0)
+              + ((corr_quad / 25) / 4)
               + __mon_yday[0][tm->tm_mon]
               + tm->tm_mday - 1);
   tm->tm_wday = ((wday % 7) + 7) % 7;