1
0
mirror of https://sourceware.org/git/glibc.git synced 2025-07-30 22:43:12 +03:00

* time/tzset.c: Optimize a bit for size.

This commit is contained in:
Ulrich Drepper
2009-03-10 17:00:17 +00:00
parent a99e59d771
commit bd82a24718
2 changed files with 45 additions and 55 deletions

View File

@ -1,3 +1,7 @@
2009-03-10 Ulrich Drepper <drepper@redhat.com>
* time/tzset.c: Optimize a bit for size.
2009-03-10 Jakub Jelinek <jakub@redhat.com> 2009-03-10 Jakub Jelinek <jakub@redhat.com>
* include/stdio.h (fmemopen): Add libc_hidden_proto. * include/stdio.h (fmemopen): Add libc_hidden_proto.
@ -19,8 +23,6 @@
(_XOPEN_VERSION): For __USE_XOPEN2K8 define to 700. (_XOPEN_VERSION): For __USE_XOPEN2K8 define to 700.
* posix/tst-sysconf.c (STDVER): Define to 200809L instead of 200112L. * posix/tst-sysconf.c (STDVER): Define to 200809L instead of 200112L.
2009-03-10 Jakub Jelinek <jakub@redhat.com>
* stdlib/quick_exit.c (quick_exit): Pass &__quick_exit_funcs * stdlib/quick_exit.c (quick_exit): Pass &__quick_exit_funcs
instead of __quick_exit_funcs to __run_exit_handlers. instead of __quick_exit_funcs to __run_exit_handlers.
* stdlib/at_quick_exit.c (at_quick_exit): Add attribute_hidden. * stdlib/at_quick_exit.c (at_quick_exit): Add attribute_hidden.

View File

@ -157,23 +157,31 @@ update_vars (void)
__tzname_cur_max = len1; __tzname_cur_max = len1;
} }
static unsigned int
__attribute_noinline__
compute_offset (unsigned int ss, unsigned int mm, unsigned int hh)
{
return min (ss, 59) + min (mm, 59) * 60 + min (hh, 24) * 60 * 60;
}
/* Parse the POSIX TZ-style string. */ /* Parse the POSIX TZ-style string. */
void void
__tzset_parse_tz (tz) __tzset_parse_tz (tz)
const char *tz; const char *tz;
{ {
register size_t l;
unsigned short int hh, mm, ss; unsigned short int hh, mm, ss;
unsigned short int whichrule;
/* Clear out old state and reset to unnamed UTC. */ /* Clear out old state and reset to unnamed UTC. */
memset (tz_rules, 0, sizeof tz_rules); memset (tz_rules, '\0', sizeof tz_rules);
tz_rules[0].name = tz_rules[1].name = ""; tz_rules[0].name = tz_rules[1].name = "";
/* Get the standard timezone name. */ /* Get the standard timezone name. */
char *tzbuf = strdupa (tz); char *tzbuf = strdupa (tz);
if (sscanf (tz, "%[A-Za-z]", tzbuf) != 1) int consumed;
if (sscanf (tz, "%[A-Za-z]%n", tzbuf, &consumed) != 1)
{ {
/* Check for the quoted version. */ /* Check for the quoted version. */
char *wp = tzbuf; char *wp = tzbuf;
@ -186,10 +194,10 @@ __tzset_parse_tz (tz)
goto out; goto out;
*wp = '\0'; *wp = '\0';
} }
else if (__builtin_expect ((l = strlen (tzbuf)) < 3, 0)) else if (__builtin_expect (consumed < 3, 0))
goto out; goto out;
else else
tz += l; tz += consumed;
tz_rules[0].name = __tzstring (tzbuf); tz_rules[0].name = __tzstring (tzbuf);
@ -201,7 +209,8 @@ __tzset_parse_tz (tz)
tz_rules[0].offset = *tz++ == '-' ? 1L : -1L; tz_rules[0].offset = *tz++ == '-' ? 1L : -1L;
else else
tz_rules[0].offset = -1L; tz_rules[0].offset = -1L;
switch (sscanf (tz, "%hu:%hu:%hu", &hh, &mm, &ss)) switch (sscanf (tz, "%hu%n:%hu%n:%hu%n",
&hh, &consumed, &mm, &consumed, &ss, &consumed))
{ {
default: default:
tz_rules[0].offset = 0; tz_rules[0].offset = 0;
@ -213,21 +222,13 @@ __tzset_parse_tz (tz)
case 3: case 3:
break; break;
} }
tz_rules[0].offset *= (min (ss, 59) + (min (mm, 59) * 60) + tz_rules[0].offset *= compute_offset (ss, mm, hh);
(min (hh, 24) * 60 * 60)); tz += consumed;
for (l = 0; l < 3; ++l)
{
while (isdigit (*tz))
++tz;
if (l < 2 && *tz == ':')
++tz;
}
/* Get the DST timezone name (if any). */ /* Get the DST timezone name (if any). */
if (*tz != '\0') if (*tz != '\0')
{ {
if (sscanf (tz, "%[A-Za-z]", tzbuf) != 1) if (sscanf (tz, "%[A-Za-z]%n", tzbuf, &consumed) != 1)
{ {
/* Check for the quoted version. */ /* Check for the quoted version. */
char *wp = tzbuf; char *wp = tzbuf;
@ -244,11 +245,11 @@ __tzset_parse_tz (tz)
*wp = '\0'; *wp = '\0';
tz = rp; tz = rp;
} }
else if (__builtin_expect ((l = strlen (tzbuf)) < 3, 0)) else if (__builtin_expect (consumed < 3, 0))
/* Punt on name, set up the offsets. */ /* Punt on name, set up the offsets. */
goto done_names; goto done_names;
else else
tz += l; tz += consumed;
tz_rules[1].name = __tzstring (tzbuf); tz_rules[1].name = __tzstring (tzbuf);
@ -258,7 +259,8 @@ __tzset_parse_tz (tz)
else else
tz_rules[1].offset = -1L; tz_rules[1].offset = -1L;
switch (sscanf (tz, "%hu:%hu:%hu", &hh, &mm, &ss)) switch (sscanf (tz, "%hu%n:%hu%n:%hu%n",
&hh, &consumed, &mm, &consumed, &ss, &consumed))
{ {
default: default:
/* Default to one hour later than standard time. */ /* Default to one hour later than standard time. */
@ -270,17 +272,10 @@ __tzset_parse_tz (tz)
case 2: case 2:
ss = 0; ss = 0;
case 3: case 3:
tz_rules[1].offset *= (min (ss, 59) + (min (mm, 59) * 60) + tz_rules[1].offset *= compute_offset (ss, mm, hh);
(min (hh, 24) * (60 * 60))); tz += consumed;
break; break;
} }
for (l = 0; l < 3; ++l)
{
while (isdigit (*tz))
++tz;
if (l < 2 && *tz == ':')
++tz;
}
if (*tz == '\0' || (tz[0] == ',' && tz[1] == '\0')) if (*tz == '\0' || (tz[0] == ',' && tz[1] == '\0'))
{ {
/* There is no rule. See if there is a default rule file. */ /* There is no rule. See if there is a default rule file. */
@ -304,7 +299,7 @@ __tzset_parse_tz (tz)
done_names: done_names:
/* Figure out the standard <-> DST rules. */ /* Figure out the standard <-> DST rules. */
for (whichrule = 0; whichrule < 2; ++whichrule) for (unsigned int whichrule = 0; whichrule < 2; ++whichrule)
{ {
register tz_rule *tzr = &tz_rules[whichrule]; register tz_rule *tzr = &tz_rules[whichrule];
@ -319,23 +314,23 @@ __tzset_parse_tz (tz)
tzr->type = *tz == 'J' ? J1 : J0; tzr->type = *tz == 'J' ? J1 : J0;
if (tzr->type == J1 && !isdigit (*++tz)) if (tzr->type == J1 && !isdigit (*++tz))
goto out; goto out;
tzr->d = (unsigned short int) strtoul (tz, &end, 10); unsigned long int d = strtoul (tz, &end, 10);
if (end == tz || tzr->d > 365) if (end == tz || d > 365)
goto out; goto out;
else if (tzr->type == J1 && tzr->d == 0) if (tzr->type == J1 && d == 0)
goto out; goto out;
tzr->d = d;
tz = end; tz = end;
} }
else if (*tz == 'M') else if (*tz == 'M')
{ {
int n;
tzr->type = M; tzr->type = M;
if (sscanf (tz, "M%hu.%hu.%hu%n", if (sscanf (tz, "M%hu.%hu.%hu%n",
&tzr->m, &tzr->n, &tzr->d, &n) != 3 || &tzr->m, &tzr->n, &tzr->d, &consumed) != 3
tzr->m < 1 || tzr->m > 12 || || tzr->m < 1 || tzr->m > 12
tzr->n < 1 || tzr->n > 5 || tzr->d > 6) || tzr->n < 1 || tzr->n > 5 || tzr->d > 6)
goto out; goto out;
tz += n; tz += consumed;
} }
else if (*tz == '\0') else if (*tz == '\0')
{ {
@ -365,7 +360,9 @@ __tzset_parse_tz (tz)
++tz; ++tz;
if (*tz == '\0') if (*tz == '\0')
goto out; goto out;
switch (sscanf (tz, "%hu:%hu:%hu", &hh, &mm, &ss)) consumed = 0;
switch (sscanf (tz, "%hu%n:%hu%n:%hu%n",
&hh, &consumed, &mm, &consumed, &ss, &consumed))
{ {
default: default:
hh = 2; /* Default to 2:00 AM. */ hh = 2; /* Default to 2:00 AM. */
@ -376,13 +373,7 @@ __tzset_parse_tz (tz)
case 3: case 3:
break; break;
} }
for (l = 0; l < 3; ++l) tz += consumed;
{
while (isdigit (*tz))
++tz;
if (l < 2 && *tz == ':')
++tz;
}
tzr->secs = (hh * 60 * 60) + (mm * 60) + ss; tzr->secs = (hh * 60 * 60) + (mm * 60) + ss;
} }
else else
@ -454,14 +445,11 @@ tzset_internal (always, explicit)
if (tz == NULL || *tz == '\0' if (tz == NULL || *tz == '\0'
|| (TZDEFAULT != NULL && strcmp (tz, TZDEFAULT) == 0)) || (TZDEFAULT != NULL && strcmp (tz, TZDEFAULT) == 0))
{ {
memset (tz_rules, '\0', sizeof tz_rules);
tz_rules[0].name = tz_rules[1].name = "UTC"; tz_rules[0].name = tz_rules[1].name = "UTC";
tz_rules[0].type = tz_rules[1].type = J0; if (J0 != 0)
tz_rules[0].m = tz_rules[0].n = tz_rules[0].d = 0; tz_rules[0].type = tz_rules[1].type = J0;
tz_rules[1].m = tz_rules[1].n = tz_rules[1].d = 0;
tz_rules[0].secs = tz_rules[1].secs = 0;
tz_rules[0].offset = tz_rules[1].offset = 0L;
tz_rules[0].change = tz_rules[1].change = (time_t) -1; tz_rules[0].change = tz_rules[1].change = (time_t) -1;
tz_rules[0].computed_for = tz_rules[1].computed_for = 0;
update_vars (); update_vars ();
return; return;
} }