*: optimize most of isXXXXX() macros

text    data     bss     dec     hex filename
 824164     453    6812  831429   cafc5 busybox_old
 823730     453    6812  830995   cae13 busybox_unstripped

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-10-23 03:16:08 +02:00
parent 7b4cd6f7b0
commit f2cbb03a37
7 changed files with 33 additions and 23 deletions

View File

@ -1173,7 +1173,7 @@ static void gen_codes(ct_data * tree, int max_code)
Tracec(tree != G2.static_ltree, Tracec(tree != G2.static_ltree,
(stderr, "\nn %3d %c l %2d c %4x (%x) ", n, (stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
(isgraph(n) ? n : ' '), len, tree[n].Code, (n > ' ' ? n : ' '), len, tree[n].Code,
next_code[len] - 1)); next_code[len] - 1));
} }
} }
@ -1541,7 +1541,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
lc = G1.l_buf[lx++]; lc = G1.l_buf[lx++];
if ((flag & 1) == 0) { if ((flag & 1) == 0) {
SEND_CODE(lc, ltree); /* send a literal byte */ SEND_CODE(lc, ltree); /* send a literal byte */
Tracecv(isgraph(lc), (stderr, " '%c' ", lc)); Tracecv(lc > ' ', (stderr, " '%c' ", lc));
} else { } else {
/* Here, lc is the match length - MIN_MATCH */ /* Here, lc is the match length - MIN_MATCH */
code = G2.length_code[lc]; code = G2.length_code[lc];

View File

@ -20,9 +20,6 @@
#include "dump.h" #include "dump.h"
#define isdecdigit(c) isdigit(c)
#define ishexdigit(c) (isxdigit)(c)
static void static void
odoffset(dumper_t *dumper, int argc, char ***argvp) odoffset(dumper_t *dumper, int argc, char ***argvp)
{ {
@ -51,8 +48,8 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
if ((*p != '+') if ((*p != '+')
&& (argc < 2 && (argc < 2
|| (!isdecdigit(p[0]) || (!isdigit(p[0])
&& ((p[0] != 'x') || !ishexdigit(p[1]))))) && ((p[0] != 'x') || !isxdigit(p[1])))))
return; return;
base = 0; base = 0;
@ -62,7 +59,7 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
*/ */
if (p[0] == '+') if (p[0] == '+')
++p; ++p;
if (p[0] == 'x' && ishexdigit(p[1])) { if (p[0] == 'x' && isxdigit(p[1])) {
++p; ++p;
base = 16; base = 16;
} else if (p[0] == '0' && p[1] == 'x') { } else if (p[0] == '0' && p[1] == 'x') {
@ -72,10 +69,10 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
/* skip over the number */ /* skip over the number */
if (base == 16) if (base == 16)
for (num = p; ishexdigit(*p); ++p) for (num = p; isxdigit(*p); ++p)
continue; continue;
else else
for (num = p; isdecdigit(*p); ++p) for (num = p; isdigit(*p); ++p)
continue; continue;
/* check for no number */ /* check for no number */

View File

@ -1566,8 +1566,11 @@ extern const char bb_default_login_shell[];
#define RB_POWER_OFF 0x4321fedc #define RB_POWER_OFF 0x4321fedc
#endif #endif
/* Make sure we call functions instead of macros. */ /* Make sure we call functions instead of these macros */
#undef isalnum #undef isalnum
#undef ispunct
#undef isxdigit
/* and these we'll redefine */
#undef isalpha #undef isalpha
#undef isascii #undef isascii
#undef isblank #undef isblank
@ -1575,25 +1578,32 @@ extern const char bb_default_login_shell[];
#undef isgraph #undef isgraph
#undef islower #undef islower
#undef isprint #undef isprint
#undef ispunct
#undef isupper #undef isupper
#undef isxdigit #undef isdigit
#undef isspace
/* This one is more efficient - we save ~500 bytes. /* This one is more efficient - we save ~500 bytes.
* BTW, x86 likes (unsigned char) cast more than (unsigned). */ * BTW, x86 likes (unsigned char) cast more than (unsigned). */
#undef isdigit
#define isdigit(a) ((unsigned char)((a) - '0') <= 9) #define isdigit(a) ((unsigned char)((a) - '0') <= 9)
/* This one is more efficient too! ~200 bytes */ #define isascii(a) ((unsigned char)(a) <= 0x7f)
#define isgraph(a) ((unsigned char)(a) > ' ')
#define isprint(a) ((unsigned char)(a) >= ' ')
#define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A'))
#define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a'))
#define isalpha(a) ((unsigned char)(((a) | 0x20) - 'a') <= ('z' - 'a'))
#define isblank(a) ({ unsigned char bb__isblank = (a); bb__isblank == ' ' || bb__isblank == '\t'; })
#define iscntrl(a) ({ unsigned char bb__iscntrl = (a); bb__iscntrl < ' ' || bb__iscntrl == 0x7f; })
/* In POSIX/C locale (the only locale we care about: do we REALLY want /* In POSIX/C locale (the only locale we care about: do we REALLY want
* to allow Unicode whitespace in, say, .conf files? nuts!) * to allow Unicode whitespace in, say, .conf files? nuts!)
* isspace is only these chars: "\t\n\v\f\r" and space. * isspace is only these chars: "\t\n\v\f\r" and space.
* "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13. * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
* Use that. * Use that.
*/ */
#undef isspace
#define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) #define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); })
#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))

View File

@ -225,19 +225,22 @@ static void get_username_or_die(char *buf, int size_buf)
/* skip whitespace */ /* skip whitespace */
do { do {
c = getchar(); c = getchar();
if (c == EOF) exit(EXIT_FAILURE); if (c == EOF)
exit(EXIT_FAILURE);
if (c == '\n') { if (c == '\n') {
if (!--cntdown) exit(EXIT_FAILURE); if (!--cntdown)
exit(EXIT_FAILURE);
goto prompt; goto prompt;
} }
} while (isspace(c)); } while (isspace(c)); /* maybe isblank? */
*buf++ = c; *buf++ = c;
if (!fgets(buf, size_buf-2, stdin)) if (!fgets(buf, size_buf-2, stdin))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
if (!strchr(buf, '\n')) if (!strchr(buf, '\n'))
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
while (isgraph(*buf)) buf++; while ((unsigned char)*buf > ' ')
buf++;
*buf = '\0'; *buf = '\0';
} }

View File

@ -841,7 +841,7 @@ static int expand_arguments(char *command)
num_skip_chars = 1; num_skip_chars = 1;
} else { } else {
src = dst + 1; src = dst + 1;
while ((isalnum)(*src) || *src == '_') src++; while (isalnum(*src) || *src == '_') src++;
} }
if (src == NULL) { if (src == NULL) {
src = dst+dstlen; src = dst+dstlen;

View File

@ -460,7 +460,7 @@ read_line(const char *prompt)
line_buffer[--sz] = '\0'; line_buffer[--sz] = '\0';
line_ptr = line_buffer; line_ptr = line_buffer;
while (*line_ptr && !isgraph(*line_ptr)) while (*line_ptr != '\0' && (unsigned char)*line_ptr <= ' ')
line_ptr++; line_ptr++;
return *line_ptr; return *line_ptr;
} }

View File

@ -122,7 +122,7 @@ int ipcrm_main(int argc, char **argv)
while ((c = getopt(argc, argv, "q:m:s:Q:M:S:h?")) != -1) { while ((c = getopt(argc, argv, "q:m:s:Q:M:S:h?")) != -1) {
int result; int result;
int id = 0; int id = 0;
int iskey = (isupper)(c); int iskey = isupper(c);
/* needed to delete semaphores */ /* needed to delete semaphores */
union semun arg; union semun arg;