From 176732ee2c7540771d2c490138238322f15b9113 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Fri, 5 Jul 2019 18:36:10 +0200 Subject: [PATCH] ModelTree: pass argument by const-reference rather than by value in some methods --- src/ModelTree.cc | 26 ++++++++++---------------- src/ModelTree.hh | 4 ++-- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/ModelTree.cc b/src/ModelTree.cc index 440236eb..609c3c63 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1965,29 +1965,23 @@ ModelTree::addAuxEquation(expr_t eq) } void -ModelTree::addTrendVariables(vector<int> trend_vars, expr_t growth_factor) noexcept(false) +ModelTree::addTrendVariables(const vector<int> &trend_vars, expr_t growth_factor) noexcept(false) { - while (!trend_vars.empty()) - if (trend_symbols_map.find(trend_vars.back()) != trend_symbols_map.end()) - throw TrendException(symbol_table.getName(trend_vars.back())); + for (int id : trend_vars) + if (trend_symbols_map.find(id) != trend_symbols_map.end()) + throw TrendException(symbol_table.getName(id)); else - { - trend_symbols_map[trend_vars.back()] = growth_factor; - trend_vars.pop_back(); - } + trend_symbols_map[id] = growth_factor; } void -ModelTree::addNonstationaryVariables(vector<int> nonstationary_vars, bool log_deflator, expr_t deflator) noexcept(false) +ModelTree::addNonstationaryVariables(const vector<int> &nonstationary_vars, bool log_deflator, expr_t deflator) noexcept(false) { - while (!nonstationary_vars.empty()) - if (nonstationary_symbols_map.find(nonstationary_vars.back()) != nonstationary_symbols_map.end()) - throw TrendException(symbol_table.getName(nonstationary_vars.back())); + for (int id : nonstationary_vars) + if (nonstationary_symbols_map.find(id) != nonstationary_symbols_map.end()) + throw TrendException(symbol_table.getName(id)); else - { - nonstationary_symbols_map[nonstationary_vars.back()] = { log_deflator, deflator }; - nonstationary_vars.pop_back(); - } + nonstationary_symbols_map[id] = { log_deflator, deflator }; } void diff --git a/src/ModelTree.hh b/src/ModelTree.hh index ae9aa026..0dc0aa5a 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -343,9 +343,9 @@ public: //! Returns the number of equations in the model int equation_number() const; //! Adds a trend variable with its growth factor - void addTrendVariables(vector<int> trend_vars, expr_t growth_factor) noexcept(false); + void addTrendVariables(const vector<int> &trend_vars, expr_t growth_factor) noexcept(false); //! Adds a nonstationary variables with their (common) deflator - void addNonstationaryVariables(vector<int> nonstationary_vars, bool log_deflator, expr_t deflator) noexcept(false); + void addNonstationaryVariables(const vector<int> &nonstationary_vars, bool log_deflator, expr_t deflator) noexcept(false); //! Is a given variable non-stationary? bool isNonstationary(int symb_id) const; void set_cutoff_to_zero(); -- GitLab