aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2009-10-23 03:16:08 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2009-10-23 03:16:08 +0200
commitf2cbb03a378aa48f2e08b64877d54da3fab4ea6a (patch)
tree35ff7449ba394e4e0a84a19a70eafa7b181d8d71
parent7b4cd6f7b07b816c4b36d686fe47c5cfec7f5abf (diff)
downloadbusybox-w32-f2cbb03a378aa48f2e08b64877d54da3fab4ea6a.tar.gz
busybox-w32-f2cbb03a378aa48f2e08b64877d54da3fab4ea6a.tar.bz2
busybox-w32-f2cbb03a378aa48f2e08b64877d54da3fab4ea6a.zip
*: 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>
-rw-r--r--archival/gzip.c4
-rw-r--r--coreutils/od.c13
-rw-r--r--include/libbb.h22
-rw-r--r--loginutils/login.c11
-rw-r--r--shell/lash_unused.c2
-rw-r--r--util-linux/fdisk.c2
-rw-r--r--util-linux/ipcrm.c2
7 files changed, 33 insertions, 23 deletions
diff --git a/archival/gzip.c b/archival/gzip.c
index 1e56c9dec..71505698c 100644
--- a/archival/gzip.c
+++ b/archival/gzip.c
@@ -1173,7 +1173,7 @@ static void gen_codes(ct_data * tree, int max_code)
1173 1173
1174 Tracec(tree != G2.static_ltree, 1174 Tracec(tree != G2.static_ltree,
1175 (stderr, "\nn %3d %c l %2d c %4x (%x) ", n, 1175 (stderr, "\nn %3d %c l %2d c %4x (%x) ", n,
1176 (isgraph(n) ? n : ' '), len, tree[n].Code, 1176 (n > ' ' ? n : ' '), len, tree[n].Code,
1177 next_code[len] - 1)); 1177 next_code[len] - 1));
1178 } 1178 }
1179} 1179}
@@ -1541,7 +1541,7 @@ static void compress_block(ct_data * ltree, ct_data * dtree)
1541 lc = G1.l_buf[lx++]; 1541 lc = G1.l_buf[lx++];
1542 if ((flag & 1) == 0) { 1542 if ((flag & 1) == 0) {
1543 SEND_CODE(lc, ltree); /* send a literal byte */ 1543 SEND_CODE(lc, ltree); /* send a literal byte */
1544 Tracecv(isgraph(lc), (stderr, " '%c' ", lc)); 1544 Tracecv(lc > ' ', (stderr, " '%c' ", lc));
1545 } else { 1545 } else {
1546 /* Here, lc is the match length - MIN_MATCH */ 1546 /* Here, lc is the match length - MIN_MATCH */
1547 code = G2.length_code[lc]; 1547 code = G2.length_code[lc];
diff --git a/coreutils/od.c b/coreutils/od.c
index e4179a36d..228db19ac 100644
--- a/coreutils/od.c
+++ b/coreutils/od.c
@@ -20,9 +20,6 @@
20 20
21#include "dump.h" 21#include "dump.h"
22 22
23#define isdecdigit(c) isdigit(c)
24#define ishexdigit(c) (isxdigit)(c)
25
26static void 23static void
27odoffset(dumper_t *dumper, int argc, char ***argvp) 24odoffset(dumper_t *dumper, int argc, char ***argvp)
28{ 25{
@@ -51,8 +48,8 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
51 48
52 if ((*p != '+') 49 if ((*p != '+')
53 && (argc < 2 50 && (argc < 2
54 || (!isdecdigit(p[0]) 51 || (!isdigit(p[0])
55 && ((p[0] != 'x') || !ishexdigit(p[1]))))) 52 && ((p[0] != 'x') || !isxdigit(p[1])))))
56 return; 53 return;
57 54
58 base = 0; 55 base = 0;
@@ -62,7 +59,7 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
62 */ 59 */
63 if (p[0] == '+') 60 if (p[0] == '+')
64 ++p; 61 ++p;
65 if (p[0] == 'x' && ishexdigit(p[1])) { 62 if (p[0] == 'x' && isxdigit(p[1])) {
66 ++p; 63 ++p;
67 base = 16; 64 base = 16;
68 } else if (p[0] == '0' && p[1] == 'x') { 65 } else if (p[0] == '0' && p[1] == 'x') {
@@ -72,10 +69,10 @@ odoffset(dumper_t *dumper, int argc, char ***argvp)
72 69
73 /* skip over the number */ 70 /* skip over the number */
74 if (base == 16) 71 if (base == 16)
75 for (num = p; ishexdigit(*p); ++p) 72 for (num = p; isxdigit(*p); ++p)
76 continue; 73 continue;
77 else 74 else
78 for (num = p; isdecdigit(*p); ++p) 75 for (num = p; isdigit(*p); ++p)
79 continue; 76 continue;
80 77
81 /* check for no number */ 78 /* check for no number */
diff --git a/include/libbb.h b/include/libbb.h
index ad0d59d04..805846391 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -1566,8 +1566,11 @@ extern const char bb_default_login_shell[];
1566#define RB_POWER_OFF 0x4321fedc 1566#define RB_POWER_OFF 0x4321fedc
1567#endif 1567#endif
1568 1568
1569/* Make sure we call functions instead of macros. */ 1569/* Make sure we call functions instead of these macros */
1570#undef isalnum 1570#undef isalnum
1571#undef ispunct
1572#undef isxdigit
1573/* and these we'll redefine */
1571#undef isalpha 1574#undef isalpha
1572#undef isascii 1575#undef isascii
1573#undef isblank 1576#undef isblank
@@ -1575,25 +1578,32 @@ extern const char bb_default_login_shell[];
1575#undef isgraph 1578#undef isgraph
1576#undef islower 1579#undef islower
1577#undef isprint 1580#undef isprint
1578#undef ispunct
1579#undef isupper 1581#undef isupper
1580#undef isxdigit 1582#undef isdigit
1583#undef isspace
1581 1584
1582/* This one is more efficient - we save ~500 bytes. 1585/* This one is more efficient - we save ~500 bytes.
1583 * BTW, x86 likes (unsigned char) cast more than (unsigned). */ 1586 * BTW, x86 likes (unsigned char) cast more than (unsigned). */
1584#undef isdigit
1585#define isdigit(a) ((unsigned char)((a) - '0') <= 9) 1587#define isdigit(a) ((unsigned char)((a) - '0') <= 9)
1586 1588
1587/* This one is more efficient too! ~200 bytes */ 1589#define isascii(a) ((unsigned char)(a) <= 0x7f)
1590#define isgraph(a) ((unsigned char)(a) > ' ')
1591#define isprint(a) ((unsigned char)(a) >= ' ')
1592#define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A'))
1593#define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a'))
1594#define isalpha(a) ((unsigned char)(((a) | 0x20) - 'a') <= ('z' - 'a'))
1595#define isblank(a) ({ unsigned char bb__isblank = (a); bb__isblank == ' ' || bb__isblank == '\t'; })
1596#define iscntrl(a) ({ unsigned char bb__iscntrl = (a); bb__iscntrl < ' ' || bb__iscntrl == 0x7f; })
1597
1588/* In POSIX/C locale (the only locale we care about: do we REALLY want 1598/* In POSIX/C locale (the only locale we care about: do we REALLY want
1589 * to allow Unicode whitespace in, say, .conf files? nuts!) 1599 * to allow Unicode whitespace in, say, .conf files? nuts!)
1590 * isspace is only these chars: "\t\n\v\f\r" and space. 1600 * isspace is only these chars: "\t\n\v\f\r" and space.
1591 * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13. 1601 * "\t\n\v\f\r" happen to have ASCII codes 9,10,11,12,13.
1592 * Use that. 1602 * Use that.
1593 */ 1603 */
1594#undef isspace
1595#define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) 1604#define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); })
1596 1605
1606
1597#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) 1607#define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0])))
1598 1608
1599 1609
diff --git a/loginutils/login.c b/loginutils/login.c
index ed2ab7f80..70e85625b 100644
--- a/loginutils/login.c
+++ b/loginutils/login.c
@@ -225,19 +225,22 @@ static void get_username_or_die(char *buf, int size_buf)
225 /* skip whitespace */ 225 /* skip whitespace */
226 do { 226 do {
227 c = getchar(); 227 c = getchar();
228 if (c == EOF) exit(EXIT_FAILURE); 228 if (c == EOF)
229 exit(EXIT_FAILURE);
229 if (c == '\n') { 230 if (c == '\n') {
230 if (!--cntdown) exit(EXIT_FAILURE); 231 if (!--cntdown)
232 exit(EXIT_FAILURE);
231 goto prompt; 233 goto prompt;
232 } 234 }
233 } while (isspace(c)); 235 } while (isspace(c)); /* maybe isblank? */
234 236
235 *buf++ = c; 237 *buf++ = c;
236 if (!fgets(buf, size_buf-2, stdin)) 238 if (!fgets(buf, size_buf-2, stdin))
237 exit(EXIT_FAILURE); 239 exit(EXIT_FAILURE);
238 if (!strchr(buf, '\n')) 240 if (!strchr(buf, '\n'))
239 exit(EXIT_FAILURE); 241 exit(EXIT_FAILURE);
240 while (isgraph(*buf)) buf++; 242 while ((unsigned char)*buf > ' ')
243 buf++;
241 *buf = '\0'; 244 *buf = '\0';
242} 245}
243 246
diff --git a/shell/lash_unused.c b/shell/lash_unused.c
index f71daf236..107ce88f6 100644
--- a/shell/lash_unused.c
+++ b/shell/lash_unused.c
@@ -841,7 +841,7 @@ static int expand_arguments(char *command)
841 num_skip_chars = 1; 841 num_skip_chars = 1;
842 } else { 842 } else {
843 src = dst + 1; 843 src = dst + 1;
844 while ((isalnum)(*src) || *src == '_') src++; 844 while (isalnum(*src) || *src == '_') src++;
845 } 845 }
846 if (src == NULL) { 846 if (src == NULL) {
847 src = dst+dstlen; 847 src = dst+dstlen;
diff --git a/util-linux/fdisk.c b/util-linux/fdisk.c
index 1bb3a9d4e..6a194fd1a 100644
--- a/util-linux/fdisk.c
+++ b/util-linux/fdisk.c
@@ -460,7 +460,7 @@ read_line(const char *prompt)
460 line_buffer[--sz] = '\0'; 460 line_buffer[--sz] = '\0';
461 461
462 line_ptr = line_buffer; 462 line_ptr = line_buffer;
463 while (*line_ptr && !isgraph(*line_ptr)) 463 while (*line_ptr != '\0' && (unsigned char)*line_ptr <= ' ')
464 line_ptr++; 464 line_ptr++;
465 return *line_ptr; 465 return *line_ptr;
466} 466}
diff --git a/util-linux/ipcrm.c b/util-linux/ipcrm.c
index 5dcda859a..5e18c2846 100644
--- a/util-linux/ipcrm.c
+++ b/util-linux/ipcrm.c
@@ -122,7 +122,7 @@ int ipcrm_main(int argc, char **argv)
122 while ((c = getopt(argc, argv, "q:m:s:Q:M:S:h?")) != -1) { 122 while ((c = getopt(argc, argv, "q:m:s:Q:M:S:h?")) != -1) {
123 int result; 123 int result;
124 int id = 0; 124 int id = 0;
125 int iskey = (isupper)(c); 125 int iskey = isupper(c);
126 126
127 /* needed to delete semaphores */ 127 /* needed to delete semaphores */
128 union semun arg; 128 union semun arg;