*: remove last function calls to isspace

function                                             old     new   delta
xstrtoul_range_sfx                                   232     231      -1
xstrtoull_range_sfx                                  295     293      -2
trim                                                  82      80      -2
trim_trailing_spaces_and_print                        57      52      -5
isspace                                               18       -     -18

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2009-10-22 22:28:08 +02:00
parent 6935ec9c0b
commit c0dab37d0a
8 changed files with 28 additions and 35 deletions

View File

@ -262,7 +262,7 @@ static void trim_trailing_spaces_and_print(char *s)
} }
while (p != s) { while (p != s) {
--p; --p;
if (!(isspace)(*p)) { /* We want the function... not the inline. */ if (!isspace(*p)) {
p[1] = '\0'; p[1] = '\0';
break; break;
} }

View File

@ -43,22 +43,19 @@
#include "libbb.h" #include "libbb.h"
#if ENABLE_LOCALE_SUPPORT #if !ENABLE_LOCALE_SUPPORT
#define isspace_given_isprint(c) isspace(c) # undef isprint
#else # undef isspace
#undef isspace # define isprint(c) ((unsigned)((c) - 0x20) <= (0x7e - 0x20))
#undef isprint # define isspace(c) ((c) == ' ')
#define isspace(c) ((((c) == ' ') || (((unsigned int)((c) - 9)) <= (13 - 9))))
#define isprint(c) (((unsigned int)((c) - 0x20)) <= (0x7e - 0x20))
#define isspace_given_isprint(c) ((c) == ' ')
#endif #endif
#if ENABLE_FEATURE_WC_LARGE #if ENABLE_FEATURE_WC_LARGE
#define COUNT_T unsigned long long # define COUNT_T unsigned long long
#define COUNT_FMT "llu" # define COUNT_FMT "llu"
#else #else
#define COUNT_T unsigned # define COUNT_T unsigned
#define COUNT_FMT "u" # define COUNT_FMT "u"
#endif #endif
enum { enum {
@ -123,11 +120,11 @@ int wc_main(int argc UNUSED_PARAM, char **argv)
c = getc(fp); c = getc(fp);
if (isprint(c)) { if (isprint(c)) {
++linepos; ++linepos;
if (!isspace_given_isprint(c)) { if (!isspace(c)) {
in_word = 1; in_word = 1;
continue; continue;
} }
} else if (((unsigned int)(c - 9)) <= 4) { } else if ((unsigned)(c - 9) <= 4) {
/* \t 9 /* \t 9
* \n 10 * \n 10
* \v 11 * \v 11

View File

@ -423,10 +423,10 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
if (*cmdstr == '\n' || *cmdstr == '\\') { if (*cmdstr == '\n' || *cmdstr == '\\') {
cmdstr++; cmdstr++;
break; break;
} else if (isspace(*cmdstr)) }
cmdstr++; if (!isspace(*cmdstr))
else
break; break;
cmdstr++;
} }
sed_cmd->string = xstrdup(cmdstr); sed_cmd->string = xstrdup(cmdstr);
/* "\anychar" -> "anychar" */ /* "\anychar" -> "anychar" */

View File

@ -1783,23 +1783,23 @@ static int st_test(char *p, int type, int dir, char *tested)
if (type == S_BEFORE_WS) { if (type == S_BEFORE_WS) {
c = ci; c = ci;
test = ((!isspace(c)) || c == '\n'); test = (!isspace(c) || c == '\n');
} }
if (type == S_TO_WS) { if (type == S_TO_WS) {
c = c0; c = c0;
test = ((!isspace(c)) || c == '\n'); test = (!isspace(c) || c == '\n');
} }
if (type == S_OVER_WS) { if (type == S_OVER_WS) {
c = c0; c = c0;
test = ((isspace(c))); test = isspace(c);
} }
if (type == S_END_PUNCT) { if (type == S_END_PUNCT) {
c = ci; c = ci;
test = ((ispunct(c))); test = ispunct(c);
} }
if (type == S_END_ALNUM) { if (type == S_END_ALNUM) {
c = ci; c = ci;
test = ((isalnum(c)) || c == '_'); test = (isalnum(c) || c == '_');
} }
*tested = c; *tested = c;
return test; return test;

View File

@ -20,9 +20,7 @@ int FAST_FUNC bb_ask_confirmation(void)
int c; int c;
while (((c = getchar()) != EOF) && (c != '\n')) { while (((c = getchar()) != EOF) && (c != '\n')) {
/* Make sure we get the actual function call for isspace, if (first && !isspace(c)) {
* as speed is not critical here. */
if (first && !(isspace)(c)) {
--first; --first;
if ((c == 'y') || (c == 'Y')) { if ((c == 'y') || (c == 'Y')) {
++retval; ++retval;

View File

@ -13,7 +13,6 @@
void FAST_FUNC trim(char *s) void FAST_FUNC trim(char *s)
{ {
size_t len = strlen(s); size_t len = strlen(s);
size_t lws;
/* trim trailing whitespace */ /* trim trailing whitespace */
while (len && isspace(s[len-1])) while (len && isspace(s[len-1]))
@ -21,10 +20,10 @@ void FAST_FUNC trim(char *s)
/* trim leading whitespace */ /* trim leading whitespace */
if (len) { if (len) {
lws = strspn(s, " \n\r\t\v"); char *nws = skip_whitespace(s);
if (lws) { if ((nws - s) != 0) {
len -= lws; len -= (nws - s);
memmove(s, s + lws, len); memmove(s, nws, len);
} }
} }
s[len] = '\0'; s[len] = '\0';

View File

@ -25,9 +25,8 @@ unsigned type FAST_FUNC xstrtou(_range_sfx)(const char *numstr, int base,
int old_errno; int old_errno;
char *e; char *e;
/* Disallow '-' and any leading whitespace. Make sure we get the /* Disallow '-' and any leading whitespace. */
* actual isspace function rather than a macro implementaion. */ if (*numstr == '-' || *numstr == '+' || isspace(*numstr))
if (*numstr == '-' || *numstr == '+' || (isspace)(*numstr))
goto inval; goto inval;
/* Since this is a lib function, we're not allowed to reset errno to 0. /* Since this is a lib function, we're not allowed to reset errno to 0.

View File

@ -697,7 +697,7 @@ static char * strsep_space(char *string, int * ix)
/* Find the end of any whitespace trailing behind /* Find the end of any whitespace trailing behind
* the token and let that be part of the token */ * the token and let that be part of the token */
while (string[*ix] && (isspace)(string[*ix]) ) { while (string[*ix] && isspace(string[*ix])) {
(*ix)++; (*ix)++;
} }