diff options
author | Denys Vlasenko | 2009-10-23 03:16:08 +0200 |
---|---|---|
committer | Denys Vlasenko | 2009-10-23 03:16:08 +0200 |
commit | f2cbb03a378aa48f2e08b64877d54da3fab4ea6a (patch) | |
tree | 35ff7449ba394e4e0a84a19a70eafa7b181d8d71 /include | |
parent | 7b4cd6f7b07b816c4b36d686fe47c5cfec7f5abf (diff) | |
download | busybox-f2cbb03a378aa48f2e08b64877d54da3fab4ea6a.zip busybox-f2cbb03a378aa48f2e08b64877d54da3fab4ea6a.tar.gz |
*: 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>
Diffstat (limited to 'include')
-rw-r--r-- | include/libbb.h | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/include/libbb.h b/include/libbb.h index ad0d59d..8058463 100644 --- a/include/libbb.h +++ b/include/libbb.h @@ -1566,8 +1566,11 @@ extern const char bb_default_login_shell[]; #define RB_POWER_OFF 0x4321fedc #endif -/* Make sure we call functions instead of macros. */ +/* Make sure we call functions instead of these macros */ #undef isalnum +#undef ispunct +#undef isxdigit +/* and these we'll redefine */ #undef isalpha #undef isascii #undef isblank @@ -1575,25 +1578,32 @@ extern const char bb_default_login_shell[]; #undef isgraph #undef islower #undef isprint -#undef ispunct #undef isupper -#undef isxdigit +#undef isdigit +#undef isspace /* This one is more efficient - we save ~500 bytes. * BTW, x86 likes (unsigned char) cast more than (unsigned). */ -#undef isdigit #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 * to allow Unicode whitespace in, say, .conf files? nuts!) * 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. */ -#undef isspace #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]))) |