From f2cbb03a378aa48f2e08b64877d54da3fab4ea6a Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Oct 2009 03:16:08 +0200 Subject: *: 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 --- include/libbb.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'include/libbb.h') 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]))) -- cgit v1.1