From 22675728aade0251c673431f0a992fe481ba4ab8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 13 Dec 2023 15:37:07 +0100 Subject: [PATCH] No longer call std::move on trivially-copyable types Automatically detected by clang-tidy with performance-move-const-arg check. Do not make the modification for Tokenizer::location type, since we have no guarantee that the type will remain trivially-copyable in the future. --- src/Bytecode.hh | 2 +- src/ComputingTasks.cc | 7 +++---- src/ComputingTasks.hh | 2 +- src/DataTree.cc | 4 ++-- src/DataTree.hh | 2 +- src/DynamicModel.cc | 11 ++++++----- src/DynamicModel.hh | 4 ++-- src/ExprNode.cc | 6 +++--- src/ModelTree.cc | 8 ++++---- src/ModelTree.hh | 4 ++-- src/ParsingDriver.cc | 6 +++--- src/SymbolTable.cc | 15 +++++++-------- src/SymbolTable.hh | 8 ++++---- src/macro/Expressions.hh | 2 +- 14 files changed, 40 insertions(+), 41 deletions(-) diff --git a/src/Bytecode.hh b/src/Bytecode.hh index 6bb2f78d..9b74c53b 100644 --- a/src/Bytecode.hh +++ b/src/Bytecode.hh @@ -1022,7 +1022,7 @@ public: Block_contain_type bc; read_member(bc.Variable); read_member(bc.Equation); - Block_Contain_.push_back(move(bc)); + Block_Contain_.push_back(bc); } if (type == BlockSimulationType::solveTwoBoundariesSimple || type == BlockSimulationType::solveTwoBoundariesComplete diff --git a/src/ComputingTasks.cc b/src/ComputingTasks.cc index c77f3142..a6f9f915 100644 --- a/src/ComputingTasks.cc +++ b/src/ComputingTasks.cc @@ -3347,10 +3347,9 @@ ConditionalForecastStatement::writeJsonOutput(ostream& output) const } PlotConditionalForecastStatement::PlotConditionalForecastStatement( - optional periods_arg, SymbolList symbol_list_arg, const SymbolTable& symbol_table_arg) : - periods {move(periods_arg)}, - symbol_list {move(symbol_list_arg)}, - symbol_table {symbol_table_arg} + const optional& periods_arg, SymbolList symbol_list_arg, + const SymbolTable& symbol_table_arg) : + periods {periods_arg}, symbol_list {move(symbol_list_arg)}, symbol_table {symbol_table_arg} { } diff --git a/src/ComputingTasks.hh b/src/ComputingTasks.hh index 05772bfc..e9d5c88e 100644 --- a/src/ComputingTasks.hh +++ b/src/ComputingTasks.hh @@ -929,7 +929,7 @@ private: const SymbolTable& symbol_table; public: - PlotConditionalForecastStatement(optional periods_arg, SymbolList symbol_list_arg, + PlotConditionalForecastStatement(const optional& periods_arg, SymbolList symbol_list_arg, const SymbolTable& symbol_table_arg); void checkPass(ModFileStructure& mod_file_struct, WarningConsolidation& warnings) override; void writeOutput(ostream& output, const string& basename, bool minimal_workspace) const override; diff --git a/src/DataTree.cc b/src/DataTree.cc index b21e63c8..49303d68 100644 --- a/src/DataTree.cc +++ b/src/DataTree.cc @@ -946,10 +946,10 @@ DataTree::strsplit(string_view str, char delim) } filesystem::path -DataTree::packageDir(string_view package) +DataTree::packageDir(const string_view& package) { filesystem::path d; - for (const auto& it : strsplit(move(package), '.')) + for (const auto& it : strsplit(package, '.')) d /= "+" + it; return d; } diff --git a/src/DataTree.hh b/src/DataTree.hh index 7968e20c..8502f3a8 100644 --- a/src/DataTree.hh +++ b/src/DataTree.hh @@ -384,7 +384,7 @@ public: and returns the path to the corresponding filesystem directory. In practice the package nesting is used for the planner_objective (stored inside +objective subdir). */ - static filesystem::path packageDir(string_view package); + static filesystem::path packageDir(const string_view& package); }; inline expr_t diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 601d9e33..bc403a0f 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -1212,7 +1212,7 @@ DynamicModel::updateVarAndTrendModel() const exit(EXIT_FAILURE); } } - trend_var.push_back(move(trend_var_symb_id)); + trend_var.push_back(trend_var_symb_id); } } @@ -1906,7 +1906,7 @@ DynamicModel::analyzePacEquationStructure(const string& name, map lineno, map eq_tags) +DynamicModel::addStaticOnlyEquation(expr_t eq, const optional& lineno, + map eq_tags) { auto beq = dynamic_cast(eq); assert(beq && beq->op_code == BinaryOpcode::equal); static_only_equations_equation_tags.add(static_only_equations.size(), move(eq_tags)); static_only_equations.push_back(beq); - static_only_equations_lineno.push_back(move(lineno)); + static_only_equations_lineno.push_back(lineno); } size_t @@ -3598,7 +3599,7 @@ DynamicModel::dynamicOnlyEquationsNbr() const } void -DynamicModel::addOccbinEquation(expr_t eq, optional lineno, map eq_tags, +DynamicModel::addOccbinEquation(expr_t eq, const optional& lineno, map eq_tags, const vector& regimes_bind, const vector& regimes_relax) { diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index e57efbaf..7d77e344 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -428,7 +428,7 @@ public: void replaceMyEquations(DynamicModel& dynamic_model) const; //! Adds an equation marked as [static] - void addStaticOnlyEquation(expr_t eq, optional lineno, map eq_tags); + void addStaticOnlyEquation(expr_t eq, const optional& lineno, map eq_tags); //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; @@ -441,7 +441,7 @@ public: auxiliary parameters have already been added to the symbol table. It also assumes that the “bind” and “relax” tags have been cleared from eq_tags. */ - void addOccbinEquation(expr_t eq, optional lineno, map eq_tags, + void addOccbinEquation(expr_t eq, const optional& lineno, map eq_tags, const vector& regimes_bind, const vector& regimes_relax); //! Writes LaTeX file with the equations of the dynamic model diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 78cf5bba..a4c6ae77 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -5697,7 +5697,7 @@ BinaryOpNode::getPacAREC( { // NOLINTNEXTLINE(clang-analyzer-core.CallAndMessage) auto [vid, lag, pid, constant] = term->matchVariableTimesConstantTimesParam(true); - linear_combination.emplace_back(vid.value(), lag, move(pid), constant); + linear_combination.emplace_back(vid.value(), lag, pid, constant); } catch (MatchFailureException& e) { @@ -9102,7 +9102,7 @@ ExprNode::matchVariableTimesConstantTimesParam(bool variable_obligatory) const matchVTCTPHelper(variable_id, lag, param_id, constant, false); if (variable_obligatory && !variable_id) throw MatchFailureException {"No variable in this expression"}; - return {move(variable_id), lag, move(param_id), constant}; + return {variable_id, lag, param_id, constant}; } void @@ -9194,7 +9194,7 @@ ExprNode::matchLinearCombinationOfVariables() const auto [variable_id, lag, param_id, constant] = term->matchVariableTimesConstantTimesParam(true); constant *= sign; - result.emplace_back(variable_id.value(), lag, move(param_id), constant); + result.emplace_back(variable_id.value(), lag, param_id, constant); } return result; } diff --git a/src/ModelTree.cc b/src/ModelTree.cc index c81824d4..bcd7de8b 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1394,13 +1394,13 @@ ModelTree::writeLatexModelFile(const string& mod_basename, const string& latex_b } void -ModelTree::addEquation(expr_t eq, optional lineno) +ModelTree::addEquation(expr_t eq, const optional& lineno) { auto beq = dynamic_cast(eq); assert(beq && beq->op_code == BinaryOpcode::equal); equations.push_back(beq); - equations_lineno.push_back(move(lineno)); + equations_lineno.push_back(lineno); } void @@ -1412,10 +1412,10 @@ ModelTree::findConstantEquationsWithoutMcpTag(map& } void -ModelTree::addEquation(expr_t eq, optional lineno, map eq_tags) +ModelTree::addEquation(expr_t eq, const optional& lineno, map eq_tags) { equation_tags.add(equations.size(), move(eq_tags)); - addEquation(eq, move(lineno)); + addEquation(eq, lineno); } void diff --git a/src/ModelTree.hh b/src/ModelTree.hh index dc6f0378..24655ac1 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -650,9 +650,9 @@ public: //! Absolute value under which a number is considered to be zero double cutoff {1e-15}; //! Declare a node as an equation of the model; also give its line number - void addEquation(expr_t eq, optional lineno); + void addEquation(expr_t eq, const optional& lineno); //! Declare a node as an equation of the model, also giving its tags - void addEquation(expr_t eq, optional lineno, map eq_tags); + void addEquation(expr_t eq, const optional& lineno, map eq_tags); //! Declare a node as an auxiliary equation of the model, adding it at the end of the list of //! auxiliary equations void addAuxEquation(expr_t eq); diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index 972ce1fb..8af7f2ea 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -2127,7 +2127,7 @@ ParsingDriver::set_optim_weights(string name, expr_t value) check_symbol_is_endogenous(name); if (var_weights.contains(name)) error("optim_weights: " + name + " declared twice"); - var_weights[move(name)] = move(value); + var_weights[move(name)] = value; } void @@ -2594,8 +2594,8 @@ ParsingDriver::plot_conditional_forecast(const optional& periods, optional iperiods; if (periods) iperiods = stoi(*periods); - mod_file->addStatement(make_unique( - move(iperiods), move(symbol_list), mod_file->symbol_table)); + mod_file->addStatement(make_unique(iperiods, move(symbol_list), + mod_file->symbol_table)); } void diff --git a/src/SymbolTable.cc b/src/SymbolTable.cc index 6b78152f..d836566d 100644 --- a/src/SymbolTable.cc +++ b/src/SymbolTable.cc @@ -585,8 +585,8 @@ SymbolTable::addDiffLeadAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_i } int -SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, optional orig_symb_id, - optional orig_lag) noexcept(false) +SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, const optional& orig_symb_id, + const optional& orig_lag) noexcept(false) { string varname {"AUX_DIFF_" + to_string(index)}; int symb_id; @@ -601,16 +601,15 @@ SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg, optional orig_ exit(EXIT_FAILURE); } - aux_vars.emplace_back(symb_id, AuxVarType::diff, move(orig_symb_id), move(orig_lag), 0, 0, - expr_arg, ""); + aux_vars.emplace_back(symb_id, AuxVarType::diff, orig_symb_id, orig_lag, 0, 0, expr_arg, ""); return symb_id; } int SymbolTable::addUnaryOpAuxiliaryVar(int index, expr_t expr_arg, string unary_op, - optional orig_symb_id, - optional orig_lag) noexcept(false) + const optional& orig_symb_id, + const optional& orig_lag) noexcept(false) { string varname {"AUX_UOP_" + to_string(index)}; int symb_id; @@ -625,8 +624,8 @@ SymbolTable::addUnaryOpAuxiliaryVar(int index, expr_t expr_arg, string unary_op, exit(EXIT_FAILURE); } - aux_vars.emplace_back(symb_id, AuxVarType::unaryOp, move(orig_symb_id), move(orig_lag), 0, 0, - expr_arg, move(unary_op)); + aux_vars.emplace_back(symb_id, AuxVarType::unaryOp, orig_symb_id, orig_lag, 0, 0, expr_arg, + move(unary_op)); return symb_id; } diff --git a/src/SymbolTable.hh b/src/SymbolTable.hh index 908914a5..01bbf91f 100644 --- a/src/SymbolTable.hh +++ b/src/SymbolTable.hh @@ -297,8 +297,8 @@ public: diffLead increases it). */ [[nodiscard]] pair unrollDiffLeadLagChain(int symb_id, int lag) const noexcept(false); //! Adds an auxiliary variable when the diff operator is encountered - int addDiffAuxiliaryVar(int index, expr_t expr_arg, optional orig_symb_id = nullopt, - optional orig_lag = nullopt) noexcept(false); + int addDiffAuxiliaryVar(int index, expr_t expr_arg, const optional& orig_symb_id = nullopt, + const optional& orig_lag = nullopt) noexcept(false); //! Takes care of timing between diff statements int addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) noexcept(false); @@ -307,8 +307,8 @@ public: int orig_lead) noexcept(false); //! An Auxiliary variable for a unary op int addUnaryOpAuxiliaryVar(int index, expr_t expr_arg, string unary_op, - optional orig_symb_id = nullopt, - optional orig_lag = nullopt) noexcept(false); + const optional& orig_symb_id = nullopt, + const optional& orig_lag = nullopt) noexcept(false); //! An auxiliary variable for a pac_expectation operator int addPacExpectationAuxiliaryVar(const string& name, expr_t expr_arg); //! An auxiliary variable for a pac_target_nonstationary operator diff --git a/src/macro/Expressions.hh b/src/macro/Expressions.hh index 1545291c..24260388 100644 --- a/src/macro/Expressions.hh +++ b/src/macro/Expressions.hh @@ -1135,7 +1135,7 @@ private: public: UnaryOp(codes::UnaryOp op_code_arg, ExpressionPtr arg_arg, Tokenizer::location location_arg) : - Expression(move(location_arg)), op_code {move(op_code_arg)}, arg {move(arg_arg)} + Expression(move(location_arg)), op_code {op_code_arg}, arg {move(arg_arg)} { } [[nodiscard]] string to_string() const noexcept override;