Turn some loop variables into const references when possible
Automatically detected by clang-tidy using performance-for-range-copy check.master
parent
3d94f1956c
commit
d635aac04a
|
@ -681,7 +681,7 @@ vector<filesystem::path>
|
|||
Configuration::getIncludePaths() const
|
||||
{
|
||||
vector<filesystem::path> include_paths;
|
||||
for (auto path : paths)
|
||||
for (const auto& path : paths)
|
||||
for (const auto& mapit : path.get_paths())
|
||||
for (const auto& vecit : mapit.second)
|
||||
include_paths.emplace_back(vecit);
|
||||
|
|
|
@ -1927,6 +1927,12 @@ ModelTree::initializeMEXCompilationWorkers(int numworkers, const filesystem::pat
|
|||
cout << "Spawning " << numworkers << " threads for compiling MEX files." << endl;
|
||||
|
||||
for (int i {0}; i < numworkers; i++)
|
||||
/* Passing the stop_token by const reference is ok (and makes clang-tidy happier),
|
||||
since the std::jthread constructor calls the lambda with the return argument of the
|
||||
get_stop_token() method, which returns a stop_token by value; hence there is no lifetime
|
||||
issue. See:
|
||||
https://stackoverflow.com/questions/72990607/const-stdstop-token-or-just-stdstop-token-as-parameter-for-thread-funct
|
||||
*/
|
||||
mex_compilation_workers.emplace_back([](const stop_token& stoken) {
|
||||
unique_lock<mutex> lk {mex_compilation_mut};
|
||||
filesystem::path output;
|
||||
|
|
|
@ -315,13 +315,13 @@ TrendComponentModelTable::writeOutput(const string& basename, ostream& output) c
|
|||
|
||||
vector<string> target_eqtags_vec = target_eqtags.at(name);
|
||||
output << "M_.trend_component." << name << ".target_eqtags = {";
|
||||
for (auto it : target_eqtags_vec)
|
||||
for (const auto& it : target_eqtags_vec)
|
||||
output << "'" << it << "';";
|
||||
output << "};" << endl;
|
||||
|
||||
vector<string> eqtags_vec = eqtags.at(name);
|
||||
output << "M_.trend_component." << name << ".target_eqn = [";
|
||||
for (auto it : target_eqtags_vec)
|
||||
for (const auto& it : target_eqtags_vec)
|
||||
output << distance(eqtags_vec.begin(), find(eqtags_vec.begin(), eqtags_vec.end(), it)) + 1
|
||||
<< " ";
|
||||
output << "];" << endl;
|
||||
|
@ -595,7 +595,7 @@ void
|
|||
VarModelTable::setLhs(map<string, vector<int>> lhs_arg)
|
||||
{
|
||||
lhs = move(lhs_arg);
|
||||
for (auto it : lhs)
|
||||
for (const auto& it : lhs)
|
||||
{
|
||||
vector<int> lhsvec;
|
||||
for (auto ids : it.second)
|
||||
|
|
|
@ -1282,7 +1282,7 @@ void
|
|||
Array::print(ostream& output, bool matlab_output) const noexcept
|
||||
{
|
||||
output << (matlab_output ? "{" : "[");
|
||||
for (bool printed_something {false}; auto e : arr)
|
||||
for (bool printed_something {false}; const auto& e : arr)
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
output << ", ";
|
||||
|
@ -1295,7 +1295,7 @@ void
|
|||
Tuple::print(ostream& output, bool matlab_output) const noexcept
|
||||
{
|
||||
output << (matlab_output ? "{" : "(");
|
||||
for (bool printed_something {false}; auto e : tup)
|
||||
for (bool printed_something {false}; const auto& e : tup)
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
output << ", ";
|
||||
|
@ -1308,7 +1308,7 @@ void
|
|||
Function::printArgs(ostream& output) const noexcept
|
||||
{
|
||||
output << "(";
|
||||
for (bool printed_something {false}; auto e : args)
|
||||
for (bool printed_something {false}; const auto& e : args)
|
||||
{
|
||||
if (exchange(printed_something, true))
|
||||
output << ", ";
|
||||
|
|
Loading…
Reference in New Issue