summaryrefslogtreecommitdiffhomepage
path: root/src/exec.c
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 18:53:39 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 18:53:39 -0600
commit93bbcf2f9a75bb5090d96ec9908594e15aa5908b (patch)
tree5069e98a1caee726174588d3522d4e85e5cbc353 /src/exec.c
parentfd782a60f3993d6ec302de669ceefbdacbf1f97a (diff)
downloadzash-93bbcf2f9a75bb5090d96ec9908594e15aa5908b.tar.gz
perf: restore cwd after a lone ( cd dir ) in-processperf/cd-inproc
A subshell whose body is a single cd now runs in the parent shell with the directory, PWD, OLDPWD and curdir saved and restored, instead of forking. On z/OS a fork costs ~0.4 ms there; the cd itself costs ~5 us. A readonly, integer or dynamic PWD/OLDPWD keeps the forked path.
Diffstat (limited to 'src/exec.c')
-rw-r--r--src/exec.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/exec.c b/src/exec.c
index 1967182..f09bea4 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -1239,7 +1239,11 @@ static bool subshell_in_process(const node *n) {
return false;
cmdinfo ci;
find_command(b->u.simple.args->plain, &ci, 0);
- return ci.kind == C_BUILTIN && (ci.bi->flags & (BI_PURE | BI_CD));
+ if (ci.kind != C_BUILTIN)
+ return false;
+ if (ci.bi->flags & BI_CD)
+ return var_is_plain("PWD") && var_is_plain("OLDPWD");
+ return (ci.bi->flags & BI_PURE) != 0;
}
/* ---- pipelines ------------------------------------------------------- */
@@ -1845,10 +1849,9 @@ static int eval_subshell(node *n, unsigned flags) {
}
if (ok && (sc.cmd.bi->flags & BI_CD)) {
int status;
- if (builtin_cd_isolated(sc.argc, sc.argv, &status)) {
- scope_pop();
- return status;
- }
+ builtin_cd_isolated(sc.argc, sc.argv, &status);
+ scope_pop();
+ return status;
}
scope_pop();
if (!ok)