diff options
| author | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 17:50:59 -0600 |
|---|---|---|
| committer | Sean Kurtz <seankurtz75@gmail.com> | 2026-11-25 17:50:59 -0600 |
| commit | fd782a60f3993d6ec302de669ceefbdacbf1f97a (patch) | |
| tree | 8111f5bf831e0a4df1be60980eaf32a00d3b45a9 /src/exec.c | |
| parent | 0ebef9da03f1952e8d0189a48cd7b946a7369f4f (diff) | |
| download | zash-fd782a60f3993d6ec302de669ceefbdacbf1f97a.tar.gz | |
perf: run a lone ( cd dir ) without forking
Diffstat (limited to 'src/exec.c')
| -rw-r--r-- | src/exec.c | 19 |
1 files changed, 13 insertions, 6 deletions
@@ -1226,11 +1226,11 @@ static int run_pure(simple_cmd *sc, output *o) { * @brief Can a subshell run without a process of its own? * * Its body has to be one command whose name is written literally, that - * name has to be a builtin which only writes output, and neither the - * subshell nor the command may redirect or assign. Then nothing the - * parent can see can change. A `fork()` copies the address space on - * z/OS, 4.7 ms against 0.3 ms for a `spawn()`, and ksh88 does not pay it - * for `( : )` either. + * name has to be a builtin which only writes output or changes directory + * state that can be restored, and neither the subshell nor the command may + * redirect or assign. Then nothing the parent can see can change. A + * `fork()` copies the address space on z/OS, 4.7 ms against 0.3 ms for a + * `spawn()`, and ksh88 does not pay it for `( : )` either. */ static bool subshell_in_process(const node *n) { const node *b = n->u.body; @@ -1239,7 +1239,7 @@ 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); + return ci.kind == C_BUILTIN && (ci.bi->flags & (BI_PURE | BI_CD)); } /* ---- pipelines ------------------------------------------------------- */ @@ -1843,6 +1843,13 @@ static int eval_subshell(node *n, unsigned flags) { scope_pop(); return status; } + if (ok && (sc.cmd.bi->flags & BI_CD)) { + int status; + if (builtin_cd_isolated(sc.argc, sc.argv, &status)) { + scope_pop(); + return status; + } + } scope_pop(); if (!ok) return exitstatus; |
