From 7529e350cf040a2169db0345ad488514d5f924a6 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 26 Mar 2017 00:10:26 +0000 Subject: [PATCH] =?UTF-8?q?small=20character=20classes=20overhaul:=20?= =?UTF-8?q?=E2=80=A2=20make=20fast=20character=20classes=20even=20faster?= =?UTF-8?q?=20by=20removing=20the=20C=5FSUBOP2=20hack=20=20=20in=20favour?= =?UTF-8?q?=20of=20a=20separate=20seldom-used=20ksh=5Fissubop2=20macro=20(?= =?UTF-8?q?which=20also=20=20=20makes=20ctype()=20side-effect-safe)=20whic?= =?UTF-8?q?h=20is=20a=20slower=20class=20(no=20change=20there)=20=E2=80=A2?= =?UTF-8?q?=20optimise=20cases=20of=20ksh=5Fisalphx=20followed=20by=20a=20?= =?UTF-8?q?ksh=5Fisalnux=20loop=20=20=20(used=20parsing=20variable=20names?= =?UTF-8?q?)=20=E2=80=A2=20remove=20a=20misleading=20comment=20in=20initct?= =?UTF-8?q?ypes()=20about=20\0=20from=20pdksh=20=E2=80=A2=20rename=20C=5FA?= =?UTF-8?q?LPHA=20to=20C=5FALPHX=20to=20make=20it=20more=20clear=20the=20u?= =?UTF-8?q?nderscore=20is=20included=20=E2=80=A2=20sprinkle=20a=20few=20or?= =?UTF-8?q?d()=20in=20there=20=E2=80=A2=20add=20new=20ksh=5Fisalpha()=20wh?= =?UTF-8?q?ich=20tests=20for=20[A-Za-z]=20(slow=20character=20class)=20?= =?UTF-8?q?=E2=80=A2=20there=20is=20no=20'=5F:\'=20drive=20on=20OS/2=20(wh?= =?UTF-8?q?ich=20inspired=20the=20whole=20changeset)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- check.t | 6 +++--- eval.c | 8 ++++---- expr.c | 9 +++++---- lex.c | 4 ++-- misc.c | 9 ++++----- sh.h | 21 ++++++++++----------- var.c | 9 +++++---- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/check.t b/check.t index ad17dff..85d58f0 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.765 2017/03/22 00:20:39 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.766 2017/03/26 00:10:21 tg Exp $ # -*- mode: sh -*- #- # Copyright © 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, @@ -30,7 +30,7 @@ # (2013/12/02 20:39:44) http://cvsweb.openbsd.org/cgi-bin/cvsweb/src/regress/bin/ksh/?sortby=date expected-stdout: - @(#)MIRBSD KSH R54 2017/03/21 + @(#)MIRBSD KSH R54 2017/03/25 description: Check version of shell. stdin: @@ -39,7 +39,7 @@ name: KSH_VERSION category: shell:legacy-no --- expected-stdout: - @(#)LEGACY KSH R54 2017/03/21 + @(#)LEGACY KSH R54 2017/03/25 description: Check version of legacy shell. stdin: diff --git a/eval.c b/eval.c index fb1f65d..6d4b94e 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.198 2017/03/11 22:49:55 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.199 2017/03/26 00:10:23 tg Exp $"); /* * string expansion @@ -1196,7 +1196,7 @@ varsub(Expand *xp, const char *sp, const char *word, } else if (ctype(c, C_SUBOP1)) { slen += 2; stype |= c; - } else if (ctype(c, C_SUBOP2)) { + } else if (ksh_issubop2(c)) { /* Note: ksh88 allows :%, :%%, etc */ slen += 2; stype = c; @@ -1304,7 +1304,7 @@ varsub(Expand *xp, const char *sp, const char *word, c = stype & 0x7F; /* test the compiler's code generator */ - if (((stype < 0x100) && (ctype(c, C_SUBOP2) || + if (((stype < 0x100) && (ksh_issubop2(c) || (((stype & 0x80) ? *xp->str == '\0' : xp->str == null) && (state != XARG || (ifs0 || xp->split ? (xp->u.strv[0] == NULL) : !hasnonempty(xp->u.strv))) ? @@ -1314,7 +1314,7 @@ varsub(Expand *xp, const char *sp, const char *word, /* expand word instead of variable value */ state = XBASE; if (Flag(FNOUNSET) && xp->str == null && !zero_ok && - (ctype(c, C_SUBOP2) || (state != XBASE && c != '+'))) + (ksh_issubop2(c) || (state != XBASE && c != '+'))) errorf(Tf_parm, sp); *stypep = stype; *slenp = slen; diff --git a/expr.c b/expr.c index f259b0c..edc22aa 100644 --- a/expr.c +++ b/expr.c @@ -2,7 +2,7 @@ /*- * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, - * 2011, 2012, 2013, 2014, 2016 + * 2011, 2012, 2013, 2014, 2016, 2017 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.90 2016/11/07 16:58:48 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.91 2017/03/26 00:10:23 tg Exp $"); #define EXPRTOK_DEFNS #include "exprtok.h" @@ -572,8 +572,9 @@ exprtoken(Expr_state *es) if (c == '\0') es->tok = END; else if (ksh_isalphx(c)) { - for (; ksh_isalnux(c); c = *cp) - cp++; + do { + c = *++cp; + } while (ksh_isalnux(c)); if (c == '[') { size_t len; diff --git a/lex.c b/lex.c index 357a320..48d6389 100644 --- a/lex.c +++ b/lex.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.231 2017/03/22 00:20:43 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.232 2017/03/26 00:10:24 tg Exp $"); /* * states while lexing word @@ -489,7 +489,7 @@ yylex(int cf) * If this is a trim operation, * treat (,|,) specially in STBRACE. */ - if (ctype(c, C_SUBOP2)) { + if (ksh_issubop2(c)) { ungetsc(c); if (Flag(FSH)) PUSH_STATE(STBRACEBOURNE); diff --git a/misc.c b/misc.c index 0407ae3..50e5388 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.252 2017/03/11 23:56:17 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.253 2017/03/26 00:10:24 tg Exp $"); #define KSH_CHVT_FLAG #ifdef MKSH_SMALL @@ -89,11 +89,10 @@ setctypes(const char *s, int t) void initctypes(void) { - setctypes(letters_uc, C_ALPHA); - setctypes(letters_lc, C_ALPHA); - chtypes['_'] |= C_ALPHA; + setctypes(letters_uc, C_ALPHX); + setctypes(letters_lc, C_ALPHX); + chtypes['_'] |= C_ALPHX; setctypes("0123456789", C_DIGIT); - /* \0 added automatically */ setctypes(TC_LEX1, C_LEX1); setctypes("*@#!$-?", C_VAR1); setctypes(TC_IFSWS, C_IFSWS); diff --git a/sh.h b/sh.h index 80dc810..6efbfc6 100644 --- a/sh.h +++ b/sh.h @@ -175,9 +175,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.797 2017/03/22 00:20:53 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.798 2017/03/26 00:10:25 tg Exp $"); #endif -#define MKSH_VERSION "R54 2017/03/21" +#define MKSH_VERSION "R54 2017/03/25" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -1243,7 +1243,7 @@ EXTERN bool really_exit; /* * fast character classes */ -#define C_ALPHA BIT(0) /* a-z_A-Z */ +#define C_ALPHX BIT(0) /* A-Za-z_ */ #define C_DIGIT BIT(1) /* 0-9 */ #define C_LEX1 BIT(2) /* \t \n\0|&;<>() */ #define C_VAR1 BIT(3) /* *@#!$-? */ @@ -1251,17 +1251,16 @@ EXTERN bool really_exit; #define C_SUBOP1 BIT(5) /* "=-+?" */ #define C_QUOTE BIT(6) /* \t\n "#$&'()*;<=>?[\]`| (needing quoting) */ #define C_IFS BIT(7) /* $IFS */ -#define C_SUBOP2 BIT(8) /* "#%" (magic, see below) */ extern unsigned char chtypes[]; -#define ctype(c, t) tobool( ((t) == C_SUBOP2) ? \ - (((c) == '#' || (c) == '%') ? 1 : 0) : \ - (chtypes[(unsigned char)(c)] & (t)) ) +#define ctype(c, t) tobool(chtypes[(unsigned char)(c)] & (t)) #define ord(c) ((int)(unsigned char)(c)) -#define ksh_isalphx(c) ctype((c), C_ALPHA) -#define ksh_isalnux(c) ctype((c), C_ALPHA | C_DIGIT) -#define ksh_isdigit(c) (((c) >= '0') && ((c) <= '9')) +#define ksh_issubop2(c) tobool((c) == ord('#') || (c) == ord('%')) +#define ksh_isalpha(c) (ctype((c), C_ALPHX) && (c) != ord('_')) +#define ksh_isalphx(c) ctype((c), C_ALPHX) +#define ksh_isalnux(c) ctype((c), C_ALPHX | C_DIGIT) +#define ksh_isdigit(c) ctype((c), C_DIGIT) #define ksh_islower(c) (((c) >= 'a') && ((c) <= 'z')) #define ksh_isupper(c) (((c) >= 'A') && ((c) <= 'Z')) #define ksh_tolower(c) (ksh_isupper(c) ? (c) - 'A' + 'a' : (c)) @@ -2424,7 +2423,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_isalphx(mksh_abspath_s[0]) && \ + (ksh_isalpha(mksh_abspath_s[0]) && \ mksh_abspath_s[1] == ':')); \ }) #define mksh_cdirsep(c) __extension__({ \ diff --git a/var.c b/var.c index 64de0f9..9790e5b 100644 --- a/var.c +++ b/var.c @@ -2,7 +2,7 @@ /*- * Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, - * 2011, 2012, 2013, 2014, 2015, 2016 + * 2011, 2012, 2013, 2014, 2015, 2016, 2017 * mirabilos * * Provided that these terms and disclaimer and all copyright notices @@ -28,7 +28,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.209 2016/11/11 23:31:39 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.210 2017/03/26 00:10:26 tg Exp $"); /*- * Variables @@ -1053,8 +1053,9 @@ skip_varname(const char *s, bool aok) size_t alen; if (s && ksh_isalphx(*s)) { - while (*++s && ksh_isalnux(*s)) - ; + do { + ++s; + } while (ksh_isalnux(*s)); if (aok && *s == '[' && (alen = array_ref_len(s))) s += alen; }