sh: Reduce unnecessary forks with eval.

The eval special builtin now runs the code with EV_EXIT if it was run
with EV_EXIT itself.

In particular, this eliminates one fork when a command substitution contains
an eval command that ends with an external program or a subshell.

This is similar to what r220978 did for functions.
This commit is contained in:
Jilles Tjoelker 2011-06-16 21:50:28 +00:00
parent 6037f89c81
commit c5aef5377c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=223163
2 changed files with 7 additions and 1 deletions

View File

@ -140,7 +140,7 @@ evalcmd(int argc, char **argv)
STPUTC('\0', concat);
p = grabstackstr(concat);
}
evalstring(p, builtin_flags & EV_TESTED);
evalstring(p, builtin_flags);
} else
exitstatus = 0;
return exitstatus;
@ -908,6 +908,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
dup2(pip[1], 1);
close(pip[1]);
}
flags &= ~EV_BACKCMD;
}
flags |= EV_EXIT;
}

View File

@ -0,0 +1,5 @@
# $FreeBSD$
# Not required by POSIX but useful for efficiency.
[ $$ = $(eval '${SH} -c echo\ \$PPID') ]