batch of optimisations

This commit is contained in:
tg 2017-04-27 20:22:28 +00:00
parent 1080008a8f
commit d54d4aab50
8 changed files with 50 additions and 67 deletions

28
edit.c
View File

@ -28,7 +28,7 @@
#ifndef MKSH_NO_CMDLINE_EDITING
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.326 2017/04/27 19:33:46 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/edit.c,v 1.327 2017/04/27 20:22:22 tg Exp $");
/*
* in later versions we might use libtermcap for this, but since external
@ -553,7 +553,7 @@ x_command_glob(int flags, char *toglob, char ***wordsp)
return (nwords);
}
#define IS_WORDC(c) (!ctype(c, C_LEX1) && (c) != '\'' && (c) != '"' && \
#define IS_WORDC(c) (!ctype(c, C_LEX1 | C_QC) && \
(c) != '`' && (c) != '=' && (c) != ':')
static int
@ -859,8 +859,8 @@ x_escape(const char *s, size_t len, int (*putbuf_func)(const char *, size_t))
int rval = 0;
while (wlen - add > 0)
if (vstrchr("\"#$&'()*:;<=>?[\\`{|}", s[add]) ||
ctype(s[add], C_IFS)) {
if (vstrchr("#*=?[\\`" ":{}", s[add]) || /*…1…*/
ctype(s[add], C_IFS | C_QC | C_DOLAR | CiQCL)) {
if (putbuf_func(s, add) != 0) {
rval = -1;
break;
@ -4470,14 +4470,13 @@ vi_cmd(int argcnt, const char *cmd)
if (histnum(-1) < 0)
return (-1);
p = *histpos();
#define issp(c) (ctype(c, C_SPACE) || (c) == '\n')
if (argcnt) {
while (*p && issp(*p))
while (ctype(*p, C_SPACE))
p++;
while (*p && --argcnt) {
while (*p && !issp(*p))
while (*p && !ctype(*p, C_SPACE))
p++;
while (*p && issp(*p))
while (ctype(*p, C_SPACE))
p++;
}
if (!*p)
@ -4487,7 +4486,7 @@ vi_cmd(int argcnt, const char *cmd)
sp = p;
inspace = false;
while (*p) {
if (issp(*p))
if (ctype(*p, C_SPACE))
inspace = true;
else if (inspace) {
inspace = false;
@ -4501,7 +4500,7 @@ vi_cmd(int argcnt, const char *cmd)
hnum = hlast;
if (vs->cursor != vs->linelen)
vs->cursor++;
while (*p && !issp(*p)) {
while (*p && !ctype(*p, C_SPACE)) {
argcnt++;
p++;
}
@ -4927,8 +4926,7 @@ forwword(int argcnt)
ncursor++;
else if (!ctype(vs->cbuf[ncursor], C_SPACE))
while (ncursor < vs->linelen &&
!ctype(vs->cbuf[ncursor], C_ALNUX) &&
!ctype(vs->cbuf[ncursor], C_SPACE))
!ctype(vs->cbuf[ncursor], C_ALNUX | C_SPACE))
ncursor++;
while (ncursor < vs->linelen &&
ctype(vs->cbuf[ncursor], C_SPACE))
@ -4953,8 +4951,7 @@ backword(int argcnt)
;
else
while (--ncursor >= 0 &&
!ctype(vs->cbuf[ncursor], C_ALNUX) &&
!ctype(vs->cbuf[ncursor], C_SPACE))
!ctype(vs->cbuf[ncursor], C_ALNUX | C_SPACE))
;
ncursor++;
}
@ -4979,8 +4976,7 @@ endword(int argcnt)
;
else
while (++ncursor < vs->linelen &&
!ctype(vs->cbuf[ncursor], C_ALNUX) &&
!ctype(vs->cbuf[ncursor], C_SPACE))
!ctype(vs->cbuf[ncursor], C_ALNUX | C_SPACE))
;
ncursor--;
}

4
expr.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.94 2017/04/27 19:33:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.95 2017/04/27 20:22:24 tg Exp $");
#define EXPRTOK_DEFNS
#include "exprtok.h"
@ -618,7 +618,7 @@ exprtoken(Expr_state *es)
goto process_tvar;
#endif
} else if (ctype(c, C_DIGIT)) {
while (c != '_' && (ctype(c, C_ALNUX) || c == '#'))
while (ctype(c, C_ALNUM) || c == '#')
c = *cp++;
strndupx(tvar, es->tokp, --cp - es->tokp, ATEMP);
process_tvar:

13
funcs.c
View File

@ -38,7 +38,7 @@
#endif
#endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.343 2017/04/27 19:33:48 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.344 2017/04/27 20:22:24 tg Exp $");
#if HAVE_KILLPG
/*
@ -746,10 +746,10 @@ bool
valid_alias_name(const char *cp)
{
while (*cp)
if (!ctype(*cp, C_ALIAS))
return (false);
else
if (ctype(*cp, C_ALIAS))
++cp;
else
return (false);
return (true);
}
@ -1067,8 +1067,7 @@ c_kill(const char **wp)
int i, n, rv, sig;
/* assume old style options if -digits or -UPPERCASE */
if ((p = wp[1]) && *p == '-' && (ctype(p[1], C_DIGIT) ||
ctype(p[1], C_UPPER))) {
if ((p = wp[1]) && *p == '-' && ctype(p[1], C_DIGIT | C_UPPER)) {
if (!(t = gettrap(p + 1, false, false))) {
bi_errorf(Tbad_sig_s, p + 1);
return (1);
@ -1419,7 +1418,7 @@ c_umask(const char **wp)
if (ctype(*cp, C_DIGIT)) {
new_umask = 0;
while (asc(*cp) >= asc('0') && asc(*cp) <= asc('7')) {
while (ctype(*cp, C_OCTAL)) {
new_umask = new_umask * 8 + ksh_numdig(*cp);
++cp;
}

11
lex.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.235 2017/04/27 19:33:51 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.236 2017/04/27 20:22:25 tg Exp $");
/*
* states while lexing word
@ -444,10 +444,9 @@ yylex(int cf)
statep->ls_adelim.num = 1;
statep->nparen = 0;
break;
} else if (ctype(c, C_DIGIT) ||
c == '('/*)*/ || c == ' ' ||
} else if (ctype(c, C_DIGIT | C_DOLAR | C_SPC) ||
/*XXX what else? */
c == '$') {
c == '('/*)*/) {
/* substring subst. */
if (c != ' ') {
*wp++ = CHAR;
@ -1275,7 +1274,7 @@ getsc_uu(void)
source->flags |= s->flags & SF_ALIAS;
s = source;
} else if (*s->u.tblp->val.s &&
(c = strnul(s->u.tblp->val.s)[-1], ctype(c, C_SPACE))) {
ctype((c = strnul(s->u.tblp->val.s)[-1]), C_SPACE)) {
/* pop source stack */
source = s = s->next;
/*
@ -1435,7 +1434,7 @@ getsc_line(Source *s)
} else if (interactive && cur_prompt == PS1) {
check_for_sole_return:
cp = Xstring(s->xs, xp);
while (*cp && ctype(*cp, C_IFSWS))
while (ctype(*cp, C_IFSWS))
++cp;
if (!*cp) {
histsave(&s->line, NULL, HIST_FLUSH, true);

4
main.c
View File

@ -34,7 +34,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.337 2017/04/27 19:33:51 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.338 2017/04/27 20:22:25 tg Exp $");
extern char **environ;
@ -491,7 +491,7 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp)
if (!(s->start = s->str = argv[argi++]))
errorf(Tf_optfoo, "", "", 'c', Treq_arg);
while (*s->str) {
if (*s->str != ' ' && ctype(*s->str, C_QUOTE))
if (ctype(*s->str, C_QUOTE))
break;
s->str++;
}

23
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.260 2017/04/27 19:33:52 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.261 2017/04/27 20:22:26 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -1072,7 +1072,8 @@ ksh_getopt(const char **argv, Getopt *go, const char *optionsp)
} else
go->optarg = NULL;
} else {
if (argv[go->optind] && ctype(argv[go->optind][0], C_DIGIT)) {
if (argv[go->optind] &&
ctype(argv[go->optind][0], C_DIGIT)) {
go->optarg = argv[go->optind++];
go->p = 0;
} else
@ -1096,7 +1097,7 @@ print_value_quoted(struct shf *shf, const char *s)
/* first, check whether any quotes are needed */
while ((c = *p++) >= 32)
if (ctype(c, C_QUOTE))
if (ctype(c, C_QUOTE | C_SPC))
inquote = false;
p = (const unsigned char *)s;
@ -2192,7 +2193,7 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int))
wc = 0;
i = 3;
while (i--)
if (ctype((c = (*fg)()), C_DIGIT) && asc(c) <= asc('7'))
if (ctype((c = (*fg)()), C_OCTAL))
wc = (wc << 3) + ksh_numdig(c);
else {
(*fp)(c);
@ -2220,17 +2221,17 @@ unbksl(bool cstyle, int (*fg)(void), void (*fp)(int))
n = 0;
while (n < i || i == -1) {
wc <<= 4;
if (ctype((c = (*fg)()), C_DIGIT))
wc += ksh_numdig(c);
else if (asc(c) >= asc('A') && asc(c) <= asc('F'))
wc += ksh_numuc(c) + 10;
else if (asc(c) >= asc('a') && asc(c) <= asc('f'))
wc += ksh_numlc(c) + 10;
else {
if (!ctype((c = (*fg)()), C_SEDEC)) {
wc >>= 4;
(*fp)(c);
break;
}
if (ctype(c, C_DIGIT))
wc += ksh_numdig(c);
else if (ctype(c, C_UPPER))
wc += ksh_numuc(c) + 10;
else
wc += ksh_numlc(c) + 10;
++n;
}
if (!n)

28
sh.h
View File

@ -175,9 +175,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.816 2017/04/27 19:19:05 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.817 2017/04/27 20:22:27 tg Exp $");
#endif
#define MKSH_VERSION "R55 2017/04/20"
#define MKSH_VERSION "R55 2017/04/27"
/* arithmetic types: C implementation */
#if !HAVE_CAN_INTTYPES
@ -1360,8 +1360,8 @@ EXTERN char ifs0;
#define C_PRINT (C_GRAPH | CiSP)
/* !"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~ POSIX punctuation */
#define C_PUNCT (CiUNDER | CiALIAS | CiSS | CiQC | CiQCL | CiQCX)
/* \x09\x0A\x20"#$&'()*;<=>?[\\]`| characters requiring quoting */
#define C_QUOTE (CiTAB | CiSP | CiNL | CiSS | CiQC | CiQCL | CiQCX)
/* \x09\x0A"#$&'()*;<=>?[\\]`| characters requiring quoting, minus space */
#define C_QUOTE (CiTAB | CiNL | CiSS | CiQC | CiQCL | CiQCX)
/* 0‥9A‥Fa‥f hexadecimal digit */
#define C_SEDEC (CiDIGIT | CiOCTAL | CiHEXLT)
/* \x09‥\x0D\x20 POSIX space class */
@ -1400,24 +1400,12 @@ EXTERN char ifs0;
/* helper functions */
#define ksh_isdash(s) tobool(ord((s)[0]) == '-' && ord((s)[1]) == '\0')
/* invariant distance even in EBCDIC */
#define ksh_tolower(c) (ksh_isupper(c) ? (c) - 'A' + 'a' : (c))
#define ksh_toupper(c) (ksh_islower(c) ? (c) - 'a' + 'A' : (c))
#define ksh_tolower(c) (ctype(c, C_UPPER) ? (c) - 'A' + 'a' : (c))
#define ksh_toupper(c) (ctype(c, C_LOWER) ? (c) - 'a' + 'A' : (c))
/* strictly speaking asc() here, but this works even in EBCDIC */
#define ksh_numdig(c) (ord(c) - ord('0'))
#define ksh_numuc(c) (asc(c) - asc('A'))
#define ksh_numlc(c) (asc(c) - asc('a'))
/* legacy functions */
#define ksh_issubop2(c) ctype((c), C_SUB2)
#define ksh_isalias(c) ctype((c), C_ALIAS)
#define ksh_isalpha(c) ctype((c), C_ALPHA)
#define ksh_isalphx(c) ctype((c), C_ALPHX)
#define ksh_isalnux(c) ctype((c), C_ALNUX)
#define ksh_isdigit(c) ctype((c), C_DIGIT)
#define ksh_islower(c) ctype((c), C_LOWER)
#define ksh_isupper(c) ctype((c), C_UPPER)
#define ksh_isspace(c) ctype((c), C_SPACE)
#define is_cfs(c) ctype((c), C_CFS)
#define is_mfs(c) ctype((c), C_MFS)
/* Argument parsing for built-in commands and getopts command */
@ -2583,7 +2571,7 @@ extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */
#define mksh_abspath(s) __extension__({ \
const char *mksh_abspath_s = (s); \
(mksh_cdirsep(mksh_abspath_s[0]) || \
(ksh_isalpha(mksh_abspath_s[0]) && \
(ctype(mksh_abspath_s[0], C_ALPHA) && \
mksh_abspath_s[1] == ':')); \
})
#define mksh_cdirsep(c) __extension__({ \
@ -2592,7 +2580,7 @@ extern int tty_init_fd(void); /* initialise tty_fd, tty_devtty */
})
#define mksh_sdirsep(s) __extension__({ \
const char *mksh_sdirsep_s = (s); \
((char *)((ksh_isalphx(mksh_sdirsep_s[0]) && \
((char *)((ctype(mksh_sdirsep_s[0], C_ALPHA) && \
mksh_sdirsep_s[1] == ':' && \
!mksh_cdirsep(mksh_sdirsep_s[2])) ? \
(mksh_sdirsep_s + 1) : strpbrk(mksh_sdirsep_s, "/\\"))); \

6
syn.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.121 2017/04/27 19:33:53 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/syn.c,v 1.122 2017/04/27 20:22:28 tg Exp $");
struct nesting_state {
int start_token; /* token than began nesting (eg, FOR) */
@ -697,10 +697,10 @@ function_body(char *name, int sALIAS,
* only allow [a-zA-Z_0-9] but this allows more as old pdkshs
* have allowed more; the following were never allowed:
* NUL TAB NL SP " $ & ' ( ) ; < = > \ ` |
* C_QUOTE covers all but adds # * ? [ ]
* C_QUOTE|C_SPC covers all but adds # * ? [ ]
*/
for (p = sname; *p; p++)
if (ctype(*p, C_QUOTE))
if (ctype(*p, C_QUOTE | C_SPC))
yyerror(Tinvname, sname, Tfunction);
/*