diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-23 13:05:03 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2009-10-23 13:05:03 +0200 |
commit | a7a1fd02cba88b47bc0faddd9ca301d58ff539cf (patch) | |
tree | a1c09c72bc37fa00a5df7d204c2336c5f1004982 | |
parent | 56b3eec162c135d69e7b0bee70f30cf6ec31aae5 (diff) | |
download | busybox-w32-a7a1fd02cba88b47bc0faddd9ca301d58ff539cf.tar.gz busybox-w32-a7a1fd02cba88b47bc0faddd9ca301d58ff539cf.tar.bz2 busybox-w32-a7a1fd02cba88b47bc0faddd9ca301d58ff539cf.zip |
eliminate all remaining users of ctype. ~600 byte large tables are gone.
function old new delta
skip_thing 253 278 +25
find_range 497 508 +11
ask 220 228 +8
...
setlocalenv 90 82 -8
bb_strtoll 84 76 -8
bb_strtol 85 77 -8
is_well_formed_var_name 75 66 -9
expand 651 641 -10
endofname 104 92 -12
buffer_fill_and_print 196 179 -17
isxdigit 18 - -18
httpd_main 729 711 -18
__GI_isxdigit 18 - -18
ispunct 20 - -20
isalnum 20 - -20
__GI_ispunct 20 - -20
__GI_isalnum 20 - -20
toupper 29 - -29
tolower 29 - -29
__GI_toupper 29 - -29
__GI_tolower 29 - -29
do_cmd 4454 4330 -124
------------------------------------------------------------------------------
(add/remove: 0/12 grow/shrink: 14/29 up/down: 81/-549) Total: -468 bytes
text data bss dec hex filename
823051 445 7548 831044 cae44 busybox_old
821970 441 7548 829959 caa07 busybox_unstripped
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | include/libbb.h | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/include/libbb.h b/include/libbb.h index 805846391..5d7426a66 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -1566,42 +1566,63 @@ 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 these macros */ | 1569 | /* We redefine ctype macros. Unicode-correct handling of char types |
1570 | * can't be done with such byte-oriented operations anyway, | ||
1571 | * we don't lose anything. | ||
1572 | */ | ||
1570 | #undef isalnum | 1573 | #undef isalnum |
1571 | #undef ispunct | ||
1572 | #undef isxdigit | ||
1573 | /* and these we'll redefine */ | ||
1574 | #undef isalpha | 1574 | #undef isalpha |
1575 | #undef isascii | 1575 | #undef isascii |
1576 | #undef isblank | 1576 | #undef isblank |
1577 | #undef iscntrl | 1577 | #undef iscntrl |
1578 | #undef isdigit | ||
1578 | #undef isgraph | 1579 | #undef isgraph |
1579 | #undef islower | 1580 | #undef islower |
1580 | #undef isprint | 1581 | #undef isprint |
1581 | #undef isupper | 1582 | #undef ispunct |
1582 | #undef isdigit | ||
1583 | #undef isspace | 1583 | #undef isspace |
1584 | #undef isupper | ||
1585 | #undef isxdigit | ||
1586 | #undef toupper | ||
1587 | #undef tolower | ||
1584 | 1588 | ||
1585 | /* This one is more efficient - we save ~500 bytes. | 1589 | /* We save ~500 bytes on isdigit alone. |
1586 | * BTW, x86 likes (unsigned char) cast more than (unsigned). */ | 1590 | * BTW, x86 likes (unsigned char) cast more than (unsigned). */ |
1587 | #define isdigit(a) ((unsigned char)((a) - '0') <= 9) | 1591 | #define isdigit(a) ((unsigned char)((a) - '0') <= 9) |
1588 | |||
1589 | #define isascii(a) ((unsigned char)(a) <= 0x7f) | 1592 | #define isascii(a) ((unsigned char)(a) <= 0x7f) |
1590 | #define isgraph(a) ((unsigned char)(a) > ' ') | 1593 | #define isgraph(a) ((unsigned char)(a) > ' ') |
1591 | #define isprint(a) ((unsigned char)(a) >= ' ') | 1594 | #define isprint(a) ((unsigned char)(a) >= ' ') |
1592 | #define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A')) | 1595 | #define isupper(a) ((unsigned char)((a) - 'A') <= ('Z' - 'A')) |
1593 | #define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a')) | 1596 | #define islower(a) ((unsigned char)((a) - 'a') <= ('z' - 'a')) |
1594 | #define isalpha(a) ((unsigned char)(((a) | 0x20) - 'a') <= ('z' - 'a')) | 1597 | #define isalpha(a) ((unsigned char)(((a)|0x20) - 'a') <= ('z' - 'a')) |
1595 | #define isblank(a) ({ unsigned char bb__isblank = (a); bb__isblank == ' ' || bb__isblank == '\t'; }) | 1598 | #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; }) | 1599 | #define iscntrl(a) ({ unsigned char bb__iscntrl = (a); bb__iscntrl < ' ' || bb__iscntrl == 0x7f; }) |
1597 | 1600 | /* In POSIX/C locale isspace is only these chars: "\t\n\v\f\r" and space. | |
1598 | /* In POSIX/C locale (the only locale we care about: do we REALLY want | ||
1599 | * to allow Unicode whitespace in, say, .conf files? nuts!) | ||
1600 | * isspace is only these chars: "\t\n\v\f\r" and space. | ||
1601 | * "\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. |
1602 | * Use that. | ||
1603 | */ | 1602 | */ |
1604 | #define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) | 1603 | #define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) |
1604 | #define isalnum(a) ({ unsigned char bb__isalnum = ((a)|0x20) - '0'; bb__isalnum <= 9 || (bb__isalnum - ('a' - '0')) <= 25; }) | ||
1605 | #define isxdigit(a) ({ unsigned char bb__isxdigit = ((a)|0x20) - '0'; bb__isxdigit <= 9 || (bb__isxdigit - ('a' - '0')) <= 5; }) | ||
1606 | // Unsafe wrt NUL! | ||
1607 | //#define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL) | ||
1608 | #define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0]) | ||
1609 | |||
1610 | #define toupper(a) bb_ascii_toupper(a) | ||
1611 | static ALWAYS_INLINE unsigned char bb_ascii_toupper(unsigned char a) | ||
1612 | { | ||
1613 | unsigned char b = a - 'a'; | ||
1614 | if (b <= ('z' - 'a')) | ||
1615 | a -= 'a' - 'A'; | ||
1616 | return a; | ||
1617 | } | ||
1618 | #define tolower(a) bb_ascii_tolower(a) | ||
1619 | static ALWAYS_INLINE unsigned char bb_ascii_tolower(unsigned char a) | ||
1620 | { | ||
1621 | unsigned char b = a - 'A'; | ||
1622 | if (b <= ('Z' - 'A')) | ||
1623 | a += 'a' - 'A'; | ||
1624 | return a; | ||
1625 | } | ||
1605 | 1626 | ||
1606 | 1627 | ||
1607 | #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) | 1628 | #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) |