When possible, use a more efficient overload of std::string::find()

Automatically detected by clang-tidy using the performance-faster-string-find
check.
master
Sébastien Villemot 2023-12-13 10:50:24 +01:00
parent d635aac04a
commit 7cfe226e58
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
4 changed files with 9 additions and 9 deletions

View File

@ -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 + "',";

View File

@ -1187,7 +1187,7 @@ ModelTree::fixNestedParenthesis(ostringstream& output, map<string, string>& 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;

View File

@ -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))

View File

@ -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;