diff options
author | Denys Vlasenko | 2009-10-23 13:03:59 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-10-23 13:03:59 +0200 |
commit | 56b3eec162c135d69e7b0bee70f30cf6ec31aae5 (patch) | |
tree | 03f73029b01cfa51e900a15f3ab5e12337ed5592 | |
parent | f2cbb03a378aa48f2e08b64877d54da3fab4ea6a (diff) | |
download | busybox-56b3eec162c135d69e7b0bee70f30cf6ec31aae5.zip busybox-56b3eec162c135d69e7b0bee70f30cf6ec31aae5.tar.gz |
small optimizations of toupper/tolower
function old new delta
in_ib 191 172 -19
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | editors/awk.c | 13 | ||||
-rw-r--r-- | networking/interface.c | 16 |
2 files changed, 11 insertions, 18 deletions
diff --git a/editors/awk.c b/editors/awk.c index 17244f9..bc1d938 100644 --- a/editors/awk.c +++ b/editors/awk.c @@ -2031,7 +2031,6 @@ static NOINLINE var *exec_builtin(node *op, var *res) { #define tspl (G.exec_builtin__tspl) - int (*to_xxx)(int); var *tv; node *an[4]; var *av[4]; @@ -2061,7 +2060,8 @@ static NOINLINE var *exec_builtin(node *op, var *res) if ((uint32_t)nargs < (info >> 30)) syntax_error(EMSG_TOO_FEW_ARGS); - switch (info & OPNMASK) { + info &= OPNMASK; + switch (info) { case B_a2: #if ENABLE_FEATURE_AWK_LIBM @@ -2126,15 +2126,12 @@ static NOINLINE var *exec_builtin(node *op, var *res) break; case B_lo: - to_xxx = tolower; - goto lo_cont; - case B_up: - to_xxx = toupper; - lo_cont: s1 = s = xstrdup(as[0]); while (*s1) { - *s1 = (*to_xxx)(*s1); + //*s1 = (info == B_up) ? toupper(*s1) : tolower(*s1); + if ((unsigned char)((*s1 | 0x20) - 'a') <= ('z' - 'a')) + *s1 = (info == B_up) ? (*s1 & 0xdf) : (*s1 | 0x20); s1++; } setvar_p(res, s); diff --git a/networking/interface.c b/networking/interface.c index fe6b23d..b64d24a 100644 --- a/networking/interface.c +++ b/networking/interface.c @@ -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++; |