Repository navigation
Commit 01b367f
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
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
| |||
0 commit comments