When possible, use a more efficient overload of std::string::find()
Automatically detected by clang-tidy using the performance-faster-string-find check.master
parent
d635aac04a
commit
7cfe226e58
|
@ -302,7 +302,7 @@ string
|
||||||
DynamicModel::reform(const string& name1) const
|
DynamicModel::reform(const string& name1) const
|
||||||
{
|
{
|
||||||
string name = name1;
|
string name = name1;
|
||||||
int pos = name.find(R"(\)", 0);
|
int pos = name.find('\\', 0);
|
||||||
while (pos >= 0)
|
while (pos >= 0)
|
||||||
{
|
{
|
||||||
if (name.substr(pos + 1, 1) != R"(\)")
|
if (name.substr(pos + 1, 1) != R"(\)")
|
||||||
|
@ -311,7 +311,7 @@ DynamicModel::reform(const string& name1) const
|
||||||
pos++;
|
pos++;
|
||||||
}
|
}
|
||||||
pos++;
|
pos++;
|
||||||
pos = name.find(R"(\)", pos);
|
pos = name.find('\\', pos);
|
||||||
}
|
}
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
@ -573,12 +573,12 @@ DynamicModel::parseIncludeExcludeEquations(const string& inc_exc_option_value, b
|
||||||
removeLeadingTrailingWhitespace(line);
|
removeLeadingTrailingWhitespace(line);
|
||||||
if (!line.empty())
|
if (!line.empty())
|
||||||
{
|
{
|
||||||
if (tags.empty() && line.find("=") != string::npos)
|
if (tags.empty() && line.find('=') != string::npos)
|
||||||
{
|
{
|
||||||
tagname_on_first_line = true;
|
tagname_on_first_line = true;
|
||||||
tags += line + "(";
|
tags += line + "(";
|
||||||
}
|
}
|
||||||
else if (line.find("'") != string::npos)
|
else if (line.find('\'') != string::npos)
|
||||||
tags += line + ",";
|
tags += line + ",";
|
||||||
else
|
else
|
||||||
tags += "'" + line + "',";
|
tags += "'" + line + "',";
|
||||||
|
|
|
@ -1187,7 +1187,7 @@ ModelTree::fixNestedParenthesis(ostringstream& output, map<string, string>& tmp_
|
||||||
else
|
else
|
||||||
varname = it->second;
|
varname = it->second;
|
||||||
str.replace(first_open_paren, matching_paren - first_open_paren + 1, varname);
|
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);
|
str.insert(insertLoc + 1, repstr);
|
||||||
hit_limit = false;
|
hit_limit = false;
|
||||||
i = -1;
|
i = -1;
|
||||||
|
|
|
@ -341,7 +341,7 @@ ParsingDriver::add_inf_constant()
|
||||||
expr_t
|
expr_t
|
||||||
ParsingDriver::add_model_variable(const string& name)
|
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 '.'");
|
error(name + " treated as a variable, but it contains a '.'");
|
||||||
|
|
||||||
check_symbol_existence_in_model_block(name);
|
check_symbol_existence_in_model_block(name);
|
||||||
|
@ -456,7 +456,7 @@ ParsingDriver::add_model_variable(int symb_id, int lag)
|
||||||
expr_t
|
expr_t
|
||||||
ParsingDriver::add_expression_variable(const string& name)
|
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 '.'");
|
error(name + " treated as a variable, but it contains a '.'");
|
||||||
|
|
||||||
if (parsing_epilogue && !mod_file->symbol_table.exists(name))
|
if (parsing_epilogue && !mod_file->symbol_table.exists(name))
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright © 2006-2022 Dynare Team
|
* Copyright © 2006-2023 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -168,7 +168,7 @@ void
|
||||||
OptionsList::writeOutput(ostream& output, const string& option_group) const
|
OptionsList::writeOutput(ostream& output, const string& option_group) const
|
||||||
{
|
{
|
||||||
// Initialize option_group as an empty struct iff the field does not exist!
|
// 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) << ",'"
|
output << "if ~isfield(" << option_group.substr(0, idx) << ",'"
|
||||||
<< option_group.substr(idx + 1) << "')" << endl;
|
<< option_group.substr(idx + 1) << "')" << endl;
|
||||||
|
|
Loading…
Reference in New Issue