Commit 7d96c6af authored by Paul Eggert's avatar Paul Eggert
Browse files

strptime: tweak division performance

* lib/strptime.c (day_of_the_week):
Redo with neither ‘%’ nor conditional branches.
parent 99e080c2
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.
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment