Use auto const & when possible to avoid copies

In several range-based for loops, implicit copies are made. Remove
that when possible, and try to shut converity up otherwise.

Fixes issues found by coverity.
This commit is contained in:
Jean-Marc Lasgouttes 2022-08-30 17:31:37 +02:00
parent 35070ecc03
commit 337cc97174
5 changed files with 10 additions and 6 deletions

View File

@ -1979,6 +1979,8 @@ bool BufferParams::writeLaTeX(otexstream & os, LaTeXFeatures & features,
if (!features.runparams().includeall && !included_children_.empty()) {
os << "\\includeonly{";
bool first = true;
// we do not use "auto const &" here, because incfile is modified later
// coverity[auto_causes_copy]
for (auto incfile : included_children_) {
FileName inc = makeAbsPath(incfile, filepath.absFileName());
string mangled = DocFileName(changeExtension(inc.absFileName(), ".tex")).

View File

@ -556,7 +556,7 @@ QString getAlias(QString name) {
has_aliases = true;
}
// check for the following aliases
for (auto alias : aliases) {
for (auto const & alias : aliases) {
if (name.contains(alias.first))
name.replace(alias.first, alias.second);
}

View File

@ -159,6 +159,8 @@ set<string> getTexFileList(string const & filename)
getVectorFromString(file.fileContents("UTF-8"), from_ascii("\n"));
// Normalise paths like /foo//bar ==> /foo/bar
// No "auto const &" because doc is modified later
// coverity[auto_causes_copy]
for (auto doc : doclist) {
doc = subst(doc, from_ascii("\r"), docstring());
while (contains(doc, from_ascii("//")))

View File

@ -2424,7 +2424,7 @@ void LatexInfo::buildEntries(bool isPatternString)
}
// Ignore language if there is math somewhere in pattern-string
if (isPatternString) {
for (auto s: usedText) {
for (auto const & s: usedText) {
// Remove entries created in previous search runs
keys.erase(s);
}

View File

@ -111,13 +111,13 @@ static string const find_python_binary()
// but we are trying hard to find a valid python binary
vector<string> const path = getEnvPath("PATH");
lyxerr << "Looking for python 3.x ...\n";
for (auto bin : path) {
for (auto const & bin : path) {
QString const dir = toqstr(bin);
string const localdir = dir.toLocal8Bit().constData();
QDir qdir(dir);
qdir.setFilter(QDir::Files | QDir::Executable);
QStringList list = qdir.entryList(QStringList("python3*"));
for (auto bin2 : list) {
for (auto const & bin2 : list) {
string const binary = "\"" + addName(localdir,
bin2.toLocal8Bit().constData()) + "\"";
command = python23_call(binary, true);
@ -155,13 +155,13 @@ static string const find_python_binary()
QString const exeName = "python2*";
#endif // _WIN32
for (auto bin : path) {
for (auto const & bin : path) {
QString const dir = toqstr(bin);
string const localdir = dir.toLocal8Bit().constData();
QDir qdir(dir);
qdir.setFilter(QDir::Files | QDir::Executable);
QStringList list = qdir.entryList(QStringList(exeName));
for (auto bin2 : list) {
for (auto const & bin2 : list) {
string const binary = "\"" + addName(localdir,
bin2.toLocal8Bit().constData()) + "\"";
command = python23_call(binary, true);