* time/tzfile.c (__tzfile_compute): Reorder code and ‘if’
to remove a goto, for clarity. Again, mostly indenting changes.
---
time/tzfile.c | 112 +++++++++++++++++++++++++-------------------------
1 file changed, 57 insertions(+), 55 deletions(-)
@@ -613,73 +613,75 @@ __tzfile_compute (__time64_t timer, int use_localtime,
transitions and no TZ string. Use the first type. */
ti = 0;
}
- else if (timecnt == 0 || timer >= transitions[timecnt - 1])
+ else
{
- /* TIMER is after the last transition. Use the TZ string if
- it is present and we can convert to the broken down structure. */
- if (__glibc_likely (tzspec != NULL)
- && __glibc_likely (__offtime (timer, 0, 0, tp) != NULL))
+ if (timecnt == 0 || timer >= transitions[timecnt - 1])
{
- /* Use the rules from the TZ string to compute the change. */
- __tz_compute (timer, tp);
- return;
- }
+ /* TIMER is after the last transition. Use the TZ string if
+ it is present and we can convert to the broken down structure. */
+ if (__glibc_likely (tzspec != NULL)
+ && __glibc_likely (__offtime (timer, 0, 0, tp) != NULL))
+ {
+ /* Use the rules from the TZ string to compute the change. */
+ __tz_compute (timer, tp);
+ return;
+ }
- i = timecnt;
- goto found;
- }
- else
- {
- /* Find the first transition after TIMER, and
- then pick the type of the transition before it. */
- tzidx lo = 0;
- tzidx hi = timecnt - 1;
- /* Assume that DST is changing twice a year and guess
- initial search spot from it. Half of a gregorian year
- has on average 365.2425 * 86400 / 2 = 15778476 seconds.
- Although i's value can be wrong if overflow occurs,
- this is harmless because it is just a guess. */
- __time64_t tdiff;
- ckd_sub (&tdiff, transitions[timecnt - 1], timer);
- ckd_add (&i, tdiff / 15778476, 0);
- if (i < timecnt)
+ i = timecnt;
+ }
+ else
{
- i = timecnt - 1 - i;
- if (timer < transitions[i])
+ /* Find the first transition after TIMER, and
+ then pick the type of the transition before it. */
+ tzidx lo = 0;
+ tzidx hi = timecnt - 1;
+ /* Assume that DST is changing twice a year and guess
+ initial search spot from it. Half of a gregorian year
+ has on average 365.2425 * 86400 / 2 = 15778476 seconds.
+ Although i's value can be wrong if overflow occurs,
+ this is harmless because it is just a guess. */
+ __time64_t tdiff;
+ ckd_sub (&tdiff, transitions[timecnt - 1], timer);
+ ckd_add (&i, tdiff / 15778476, 0);
+ if (i < timecnt)
{
- if (i < 10 || timer >= transitions[i - 10])
+ i = timecnt - 1 - i;
+ if (timer < transitions[i])
{
- /* Linear search. */
- while (timer < transitions[i - 1])
- --i;
- goto found;
+ if (i < 10 || timer >= transitions[i - 10])
+ {
+ /* Linear search. */
+ while (timer < transitions[i - 1])
+ --i;
+ goto found;
+ }
+ hi = i - 10;
}
- hi = i - 10;
- }
- else
- {
- if (timecnt - i <= 10 || timer < transitions[i + 10])
+ else
{
- /* Linear search. */
- while (timer >= transitions[i])
- ++i;
- goto found;
+ if (timecnt - i <= 10 || timer < transitions[i + 10])
+ {
+ /* Linear search. */
+ while (timer >= transitions[i])
+ ++i;
+ goto found;
+ }
+ lo = i + 10;
}
- lo = i + 10;
}
- }
- /* Binary search. */
- /* assert (timer >= transitions[lo] && timer < transitions[hi]); */
- while (lo + 1 < hi)
- {
- i = (lo >> 1) + (hi >> 1) + (lo & hi & 1);
- if (timer < transitions[i])
- hi = i;
- else
- lo = i;
+ /* Binary search. */
+ /* assert (timer >= transitions[lo] && timer < transitions[hi]); */
+ while (lo + 1 < hi)
+ {
+ i = (lo >> 1) + (hi >> 1) + (lo & hi & 1);
+ if (timer < transitions[i])
+ hi = i;
+ else
+ lo = i;
+ }
+ i = hi;
}
- i = hi;
found:
ti = type_idxs[i - 1];