From: Paul Eggert Date: Tue, 24 Dec 2019 07:53:23 +0000 (-0800) Subject: strptime: tweak division performance X-Git-Tag: v1.0~4427 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=7d96c6af2b60538da1267528cb917bd496f95854;p=gnulib.git strptime: tweak division performance * lib/strptime.c (day_of_the_week): Redo with neither ‘%’ nor conditional branches. --- diff --git a/ChangeLog b/ChangeLog index 4b47142040..168037ed11 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,20 +1,15 @@ 2019-12-23 Paul Eggert - 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 setlocale-null: Export the lock function also on non-Windows platforms. diff --git a/lib/strptime.c b/lib/strptime.c index e6d405a442..9c2c2e38b1 100644 --- a/lib/strptime.c +++ b/lib/strptime.c @@ -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;