Skip to content

Commit 01b367f

Browse files
committed
Fix performance with extreme TZif transitions
If the TZif file’s first transition was far in the past, or its last transition was far in the future, localtime.c code iterated to get to the extreme value, and this could take some time. Use division to avoid the need for repeated subtraction. On one test this improved performance by a factor of 100. Problem reported by David Sarkisyan. * localtime.c (struct state.goback): Remove. All uses removed. (transtime): First arg is now time_t, not int; callers need this for greater range. All callers changed. Adjust implementation to deal with possibility that time_t is unsigned. (tzparse): Don’t assume year-related locals fit in int; make them time_t instead. Don’t let them go negative if time_t is unsigned. Efficiently navigate to near atlo by using division rather than a loop that can take some time in the worst case. (localsub, gmtsub, timesub, time2sub, time2, time1): New arg ltm_year; if nonnull, put the year-1900 there rather than in tmp->tm_year. This avoids the possibility of overflow in year calculations. All callers changed. (localsub, timesub): Widen locals accordingly. (localsub): Simplify now that we no longer have goback. (increment_overflow): Remove; no longer used.
1 parent 78733a5 commit 01b367f

2 files changed

Lines changed: 83 additions & 113 deletions

File tree

‎NEWS‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Unreleased, experimental changes
5858

5959
localtime-related functions no longer mishandle extreme timestamps
6060
when given TZif files holding some unlikely timezone histories.
61+
(Problem reported by David Sarkisyan.)
6162

6263
Changes to documentation
6364

0 commit comments

Comments
 (0)