From 7cfe226e580968553ce52b482feda66a2288d451 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 13 Dec 2023 10:50:24 +0100 Subject: [PATCH] When possible, use a more efficient overload of std::string::find() Automatically detected by clang-tidy using the performance-faster-string-find check. --- src/DynamicModel.cc | 8 ++++---- src/ModelTree.cc | 2 +- src/ParsingDriver.cc | 4 ++-- src/Statement.cc | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 9e807072..601d9e33 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -302,7 +302,7 @@ string DynamicModel::reform(const string& name1) const { string name = name1; - int pos = name.find(R"(\)", 0); + int pos = name.find('\\', 0); while (pos >= 0) { if (name.substr(pos + 1, 1) != R"(\)") @@ -311,7 +311,7 @@ DynamicModel::reform(const string& name1) const pos++; } pos++; - pos = name.find(R"(\)", pos); + pos = name.find('\\', pos); } return name; } @@ -573,12 +573,12 @@ DynamicModel::parseIncludeExcludeEquations(const string& inc_exc_option_value, b removeLeadingTrailingWhitespace(line); if (!line.empty()) { - if (tags.empty() && line.find("=") != string::npos) + if (tags.empty() && line.find('=') != string::npos) { tagname_on_first_line = true; tags += line + "("; } - else if (line.find("'") != string::npos) + else if (line.find('\'') != string::npos) tags += line + ","; else tags += "'" + line + "',"; diff --git a/src/ModelTree.cc b/src/ModelTree.cc index 885ee717..c81824d4 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1187,7 +1187,7 @@ ModelTree::fixNestedParenthesis(ostringstream& output, map& tmp_ else varname = it->second; str.replace(first_open_paren, matching_paren - first_open_paren + 1, varname); - size_t insertLoc = str.find_last_of("\n", first_open_paren); + size_t insertLoc = str.find_last_of('\n', first_open_paren); str.insert(insertLoc + 1, repstr); hit_limit = false; i = -1; diff --git a/src/ParsingDriver.cc b/src/ParsingDriver.cc index ae2c74cf..972ce1fb 100644 --- a/src/ParsingDriver.cc +++ b/src/ParsingDriver.cc @@ -341,7 +341,7 @@ ParsingDriver::add_inf_constant() expr_t ParsingDriver::add_model_variable(const string& name) { - if (name.find(".") != string::npos) + if (name.find('.') != string::npos) error(name + " treated as a variable, but it contains a '.'"); check_symbol_existence_in_model_block(name); @@ -456,7 +456,7 @@ ParsingDriver::add_model_variable(int symb_id, int lag) expr_t ParsingDriver::add_expression_variable(const string& name) { - if (name.find(".") != string::npos) + if (name.find('.') != string::npos) error(name + " treated as a variable, but it contains a '.'"); if (parsing_epilogue && !mod_file->symbol_table.exists(name)) diff --git a/src/Statement.cc b/src/Statement.cc index e8d568f2..42c9b1e4 100644 --- a/src/Statement.cc +++ b/src/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright © 2006-2022 Dynare Team + * Copyright © 2006-2023 Dynare Team * * This file is part of Dynare. * @@ -168,7 +168,7 @@ void OptionsList::writeOutput(ostream& output, const string& option_group) const { // Initialize option_group as an empty struct iff the field does not exist! - if (size_t idx = option_group.find_last_of("."); idx != string::npos) + if (size_t idx = option_group.find_last_of('.'); idx != string::npos) { output << "if ~isfield(" << option_group.substr(0, idx) << ",'" << option_group.substr(idx + 1) << "')" << endl;