ash: [EXPAND] Optimise nulonly away and just use quoted as before

Upstream commit:

    Date: Wed, 8 Oct 2014 20:09:56 +0800
    [EXPAND] Optimise nulonly away and just use quoted as before

    This patch makes a small optimisation by using the same value for
    quoted between evalvar and varvalue by eliminating nulonly and
    passing along quoted instead.

    Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2016-10-01 21:02:06 +02:00
parent 88ac97d02d
commit 0dd8e45d42

View File

@ -6606,22 +6606,19 @@ subevalvar(char *p, char *varname, int strloc, int subtype,
* ash -c 'echo ${#1#}' name:'1=#' * ash -c 'echo ${#1#}' name:'1=#'
*/ */
static NOINLINE ssize_t static NOINLINE ssize_t
varvalue(char *name, int varflags, int flags, struct strlist *var_str_list, int *nulonly) varvalue(char *name, int varflags, int flags, struct strlist *var_str_list, int *quotedp)
{ {
const char *p; const char *p;
int num; int num;
int i; int i;
ssize_t len = 0; ssize_t len = 0;
int sep; int sep;
int quoted = flags & EXP_QUOTED; int quoted = *quotedp;
int subtype = varflags & VSTYPE; int subtype = varflags & VSTYPE;
int discard = subtype == VSPLUS || subtype == VSLENGTH; int discard = subtype == VSPLUS || subtype == VSLENGTH;
int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL; int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL;
int syntax = quoted ? DQSYNTAX : BASESYNTAX; int syntax = quoted ? DQSYNTAX : BASESYNTAX;
sep = *nulonly ? (flags & EXP_FULL) << CHAR_BIT : 0;
*nulonly = 0;
switch (*name) { switch (*name) {
case '$': case '$':
num = rootpid; num = rootpid;
@ -6658,6 +6655,7 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list, int
char **ap; char **ap;
char sepc; char sepc;
sep = 0;
if (quoted && (flags & EXP_FULL)) { if (quoted && (flags & EXP_FULL)) {
/* note: this is not meant as PEOF value */ /* note: this is not meant as PEOF value */
sep = 1 << CHAR_BIT; sep = 1 << CHAR_BIT;
@ -6665,11 +6663,14 @@ varvalue(char *name, int varflags, int flags, struct strlist *var_str_list, int
} }
/* fall through */ /* fall through */
case '*': case '*':
sep |= ifsset() ? (unsigned char)(ifsval()[0]) : ' '; sep = ifsset() ? (unsigned char)(ifsval()[0]) : ' ';
if (!quoted) {
param: param:
ap = shellparam.p; sep |= (flags & EXP_FULL) << CHAR_BIT;
}
sepc = sep; sepc = sep;
*nulonly = !sepc; *quotedp = !sepc;
ap = shellparam.p;
if (!ap) if (!ap)
return -1; return -1;
while ((p = *ap++) != NULL) { while ((p = *ap++) != NULL) {
@ -6759,7 +6760,6 @@ evalvar(char *p, int flag, struct strlist *var_str_list)
char subtype; char subtype;
int quoted; int quoted;
char easy; char easy;
int nulonly;
char *var; char *var;
int patloc; int patloc;
int startloc; int startloc;
@ -6770,12 +6770,11 @@ evalvar(char *p, int flag, struct strlist *var_str_list)
quoted = flag & EXP_QUOTED; quoted = flag & EXP_QUOTED;
var = p; var = p;
easy = (!quoted || (*var == '@' && shellparam.nparam)); easy = (!quoted || (*var == '@' && shellparam.nparam));
nulonly = easy;
startloc = expdest - (char *)stackblock(); startloc = expdest - (char *)stackblock();
p = strchr(p, '=') + 1; //TODO: use var_end(p)? p = strchr(p, '=') + 1; //TODO: use var_end(p)?
again: again:
varlen = varvalue(var, varflags, flag, var_str_list, &nulonly); varlen = varvalue(var, varflags, flag, var_str_list, &quoted);
if (varflags & VSNUL) if (varflags & VSNUL)
varlen--; varlen--;
@ -6824,7 +6823,7 @@ evalvar(char *p, int flag, struct strlist *var_str_list)
record: record:
if (!easy) if (!easy)
goto end; goto end;
recordregion(startloc, expdest - (char *)stackblock(), nulonly); recordregion(startloc, expdest - (char *)stackblock(), quoted);
goto end; goto end;
} }