Le 26/09/2024 à 17:08, scan-ad...@coverity.com a écrit :
*** CID 445094: Performance inefficiencies (COPY_INSTEAD_OF_MOVE)
/home/lasgoutt/src/lyx/coverity/lyx/src/frontends/qt/GuiBibtex.cpp: 327 in
lyx::frontend::GuiBibtex::relAbsPressed()()
321 for (QString s : selected_bibs_) {
322 if (s == qf)
323 sb << new_item;
324 else
325 sb << s;
326 }
CID 445094: Performance inefficiencies (COPY_INSTEAD_OF_MOVE)
"sb" is copied in a call to copy assignment "operator =", when it could be
moved instead.
327 selected_bibs_ = sb;
Jürgen, it seems to me that it is possible to modify the string in place
instead of duplicating the list. I the patch below correct? I do not
know how to test it.
JMarc
From 286623cd5ddd2879f096637de9bdbb7ebaa95ac3 Mon Sep 17 00:00:00 2001
From: Jean-Marc Lasgouttes <lasgout...@lyx.org>
Date: Sun, 29 Sep 2024 21:45:08 +0200
Subject: [PATCH] Modify string list in place instead of copying it
Spotted by Coverity scan.
---
src/frontends/qt/GuiBibtex.cpp | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/frontends/qt/GuiBibtex.cpp b/src/frontends/qt/GuiBibtex.cpp
index 47dda81032..e6eff146f5 100644
--- a/src/frontends/qt/GuiBibtex.cpp
+++ b/src/frontends/qt/GuiBibtex.cpp
@@ -317,14 +317,10 @@ void GuiBibtex::relAbsPressed()
QString const new_item = (p == LP_Absolute)
? toqstr(file.relPath(buffer().filePath()))
: toqstr(file.absoluteFilePath());
- QStringList sb;
- for (QString s : selected_bibs_) {
+ for (QString & s : selected_bibs_) {
if (s == qf)
- sb << new_item;
- else
- sb << s;
+ s = new_item;
}
- selected_bibs_ = sb;
setSelectedBibs(selected_bibs_);
selectedLV->selectRow(selected_bibs_.indexOf(new_item));
changed();
--
2.43.0
--
lyx-devel mailing list
lyx-devel@lists.lyx.org
http://lists.lyx.org/mailman/listinfo/lyx-devel