>From 6f9ead5181f2c117b3c5a4c965fe44dc1258661b Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Mon, 23 Dec 2019 23:53:23 -0800 Subject: [PATCH 4/4] strptime: tweak division performance MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lib/strptime.c (day_of_the_week): Redo with neither ‘%’ nor conditional branches. --- ChangeLog | 17 ++++++----------- lib/strptime.c | 7 ++++--- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4b4714204..168037ed1 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 e6d405a44..9c2c2e38b 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; -- 2.17.1