summaryrefslogtreecommitdiffhomepage
path: root/src/var.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/var.c
parentfd782a60f3993d6ec302de669ceefbdacbf1f97a (diff)
downloadzash-perf/cd-inproc.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/var.c')
-rw-r--r--src/var.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/var.c b/src/var.c
index def6978..d4251cf 100644
--- a/src/var.c
+++ b/src/var.c
@@ -226,6 +226,17 @@ void var_set(const char *name, const char *value, unsigned flags) {
}
/**
+ * @brief Can var_set() replace this variable without a side effect or error?
+ *
+ * A readonly, integer or dynamic variable is not plain: setting it raises,
+ * converts the text, or calls a setter.
+ */
+bool var_is_plain(const char *name) {
+ var *v = var_find(name, strlen(name), false);
+ return !v || !(v->flags & (V_READONLY | V_INTEGER | V_DYNAMIC));
+}
+
+/**
* @brief Assign a number to a variable.
*/
void var_set_long(const char *name, long value) {