From 2f1e5727561783041af5721dcb80824c5c03d806 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 10 Apr 2019 16:47:43 -0700 Subject: [PATCH] Minor cleanup of env_node_t Mark some fields const that don't need to change. Trying to get ready to improve locking here. --- src/env.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 2bd72e2cd..729f982bc 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -81,9 +81,10 @@ class env_node_t { /// or does it redefine any variables to not be exported? bool exportv = false; /// Pointer to next level. - std::shared_ptr next; + const std::shared_ptr next; - env_node_t(bool is_new_scope) : new_scope(is_new_scope) {} + env_node_t(bool is_new_scope, std::shared_ptr next_scope) + : new_scope(is_new_scope), next(std::move(next_scope)) {} maybe_t find_entry(const wcstring &key) { auto it = env.find(key); @@ -107,7 +108,7 @@ struct var_stack_t { env_node_ref_t top; // Bottom node on the function stack. - env_node_ref_t global_env; + const env_node_ref_t global_env; // Exported variable array used by execv. maybe_t> export_array; @@ -129,7 +130,7 @@ struct var_stack_t { // Pushes a new node onto our stack // Optionally creates a new scope for the node void push(bool new_scope) { - auto node = std::make_shared(new_scope); + auto node = std::make_shared(new_scope, this->top); // Copy local-exported variables. auto top_node = top; @@ -141,7 +142,6 @@ struct var_stack_t { } } - node->next = this->top; this->top = std::move(node); if (new_scope && local_scope_exports(this->top)) { this->mark_changed_exported(); @@ -193,7 +193,7 @@ struct var_stack_t { /// Returns the global variable set. static env_node_ref_t globals() { - static env_node_ref_t s_globals{std::make_shared(false)}; + static env_node_ref_t s_globals{std::make_shared(false, nullptr)}; return s_globals; } };