small optimizations of toupper/tolower

function                                             old     new   delta
in_ib                                                191     172     -19

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko
2009-10-23 13:03:59 +02:00
parent f2cbb03a37
commit 56b3eec162
2 changed files with 11 additions and 18 deletions

View File

@ -1242,10 +1242,8 @@ int FAST_FUNC in_ib(const char *bufp, struct sockaddr *sap)
c = *bufp++;
if (isdigit(c))
val = c - '0';
else if (c >= 'a' && c <= 'f')
val = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val = c - 'A' + 10;
else if ((c|0x20) >= 'a' && (c|0x20) <= 'f')
val = (c|0x20) - ('a' - 10);
else {
errno = EINVAL;
return -1;
@ -1254,17 +1252,15 @@ int FAST_FUNC in_ib(const char *bufp, struct sockaddr *sap)
c = *bufp;
if (isdigit(c))
val |= c - '0';
else if (c >= 'a' && c <= 'f')
val |= c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
val |= c - 'A' + 10;
else if (c == ':' || c == 0)
else if ((c|0x20) >= 'a' && (c|0x20) <= 'f')
val |= (c|0x20) - ('a' - 10);
else if (c == ':' || c == '\0')
val >>= 4;
else {
errno = EINVAL;
return -1;
}
if (c != 0)
if (c != '\0')
bufp++;
*ptr++ = (unsigned char) (val & 0377);
i++;