diff options
author | Denys Vlasenko | 2009-10-23 13:05:03 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-10-23 13:05:03 +0200 |
commit | a7a1fd02cba88b47bc0faddd9ca301d58ff539cf (patch) | |
tree | a1c09c72bc37fa00a5df7d204c2336c5f1004982 /include/libbb.h | |
parent | 56b3eec162c135d69e7b0bee70f30cf6ec31aae5 (diff) | |
download | busybox-a7a1fd02cba88b47bc0faddd9ca301d58ff539cf.zip busybox-a7a1fd02cba88b47bc0faddd9ca301d58ff539cf.tar.gz |
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>
Diffstat (limited to 'include/libbb.h')
-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 8058463..5d7426a 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1566,42 +1566,63 @@ extern const char bb_default_login_shell[]; #define RB_POWER_OFF 0x4321fedc #endif -/* Make sure we call functions instead of these macros */ +/* We redefine ctype macros. Unicode-correct handling of char types + * can't be done with such byte-oriented operations anyway, + * we don't lose anything. + */ #undef isalnum -#undef ispunct -#undef isxdigit -/* and these we'll redefine */ #undef isalpha #undef isascii #undef isblank #undef iscntrl +#undef isdigit #undef isgraph #undef islower #undef isprint -#undef isupper -#undef isdigit +#undef ispunct #undef isspace +#undef isupper +#undef isxdigit +#undef toupper +#undef tolower -/* This one is more efficient - we save ~500 bytes. +/* We save ~500 bytes on isdigit alone. * BTW, x86 likes (unsigned char) cast more than (unsigned). */ #define isdigit(a) ((unsigned char)((a) - '0') <= 9) - #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 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 - * to allow Unicode whitespace in, say, .conf files? nuts!) - * isspace is only these chars: "\t\n\v\f\r" and space. +/* In POSIX/C locale 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. - * Use that. */ #define isspace(a) ({ unsigned char bb__isspace = (a) - 9; bb__isspace == (' ' - 9) || bb__isspace <= (13 - 9); }) +#define isalnum(a) ({ unsigned char bb__isalnum = ((a)|0x20) - '0'; bb__isalnum <= 9 || (bb__isalnum - ('a' - '0')) <= 25; }) +#define isxdigit(a) ({ unsigned char bb__isxdigit = ((a)|0x20) - '0'; bb__isxdigit <= 9 || (bb__isxdigit - ('a' - '0')) <= 5; }) +// Unsafe wrt NUL! +//#define ispunct(a) (strchr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a)) != NULL) +#define ispunct(a) (strchrnul("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", (a))[0]) + +#define toupper(a) bb_ascii_toupper(a) +static ALWAYS_INLINE unsigned char bb_ascii_toupper(unsigned char a) +{ + unsigned char b = a - 'a'; + if (b <= ('z' - 'a')) + a -= 'a' - 'A'; + return a; +} +#define tolower(a) bb_ascii_tolower(a) +static ALWAYS_INLINE unsigned char bb_ascii_tolower(unsigned char a) +{ + unsigned char b = a - 'A'; + if (b <= ('Z' - 'A')) + a += 'a' - 'A'; + return a; +} #define ARRAY_SIZE(x) ((unsigned)(sizeof(x) / sizeof((x)[0]))) |