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:
parent
6037f89c81
commit
c5aef5377c
@ -140,7 +140,7 @@ evalcmd(int argc, char **argv)
|
|||||||
STPUTC('\0', concat);
|
STPUTC('\0', concat);
|
||||||
p = grabstackstr(concat);
|
p = grabstackstr(concat);
|
||||||
}
|
}
|
||||||
evalstring(p, builtin_flags & EV_TESTED);
|
evalstring(p, builtin_flags);
|
||||||
} else
|
} else
|
||||||
exitstatus = 0;
|
exitstatus = 0;
|
||||||
return exitstatus;
|
return exitstatus;
|
||||||
@ -908,6 +908,7 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
|
|||||||
dup2(pip[1], 1);
|
dup2(pip[1], 1);
|
||||||
close(pip[1]);
|
close(pip[1]);
|
||||||
}
|
}
|
||||||
|
flags &= ~EV_BACKCMD;
|
||||||
}
|
}
|
||||||
flags |= EV_EXIT;
|
flags |= EV_EXIT;
|
||||||
}
|
}
|
||||||
|
5
tools/regression/bin/sh/expansion/cmdsubst11.0
Normal file
5
tools/regression/bin/sh/expansion/cmdsubst11.0
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# $FreeBSD$
|
||||||
|
|
||||||
|
# Not required by POSIX but useful for efficiency.
|
||||||
|
|
||||||
|
[ $$ = $(eval '${SH} -c echo\ \$PPID') ]
|
Loading…
x
Reference in New Issue
Block a user