diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-29 13:50:32 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-30 17:14:09 +0100 |
commit | 66af11c6cba24233aa0fad49bb2de965e3285ba1 (patch) | |
tree | 72e67674d3fb381b3c89d0543390c31e89c4005b | |
parent | 7d2eecea4fd26d77dd0ac4f8e65f3073a07618ff (diff) |
Avoid various inefficiencies
Coverity-Id: 435555
Coverity-Id: 435556
Coverity-Id: 435557
Coverity-Id: 435559
Coverity-Id: 435561
Coverity-Id: 435562
Coverity-Id: 435563
Coverity-Id: 435564
Coverity-Id: 435565
Coverity-Id: 435566
Coverity-Id: 435567
Coverity-Id: 435568
Coverity-Id: 435569
Change-Id: If482bde0189b72297f09e3ff28c825364d68fd89
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
-rw-r--r-- | src/qmlcompiler/qqmljstypepropagator.cpp | 2 | ||||
-rw-r--r-- | src/qmldom/qqmldomoutwriter.cpp | 14 | ||||
-rw-r--r-- | src/qmldom/qqmldomoutwriter_p.h | 9 | ||||
-rw-r--r-- | src/qmldom/qqmldomstringdumper_p.h | 2 | ||||
-rw-r--r-- | src/qmldom/qqmldomtop.cpp | 7 | ||||
-rw-r--r-- | src/qmldom/qqmldomtop_p.h | 2 | ||||
-rw-r--r-- | tools/qmlformat/qmlformat.cpp | 2 |
7 files changed, 21 insertions, 17 deletions
diff --git a/src/qmlcompiler/qqmljstypepropagator.cpp b/src/qmlcompiler/qqmljstypepropagator.cpp index beb846bf81..25a6b3a854 100644 --- a/src/qmlcompiler/qqmljstypepropagator.cpp +++ b/src/qmlcompiler/qqmljstypepropagator.cpp @@ -1000,7 +1000,7 @@ void QQmlJSTypePropagator::generate_StoreProperty(int nameIndex, int base) const QQmlJSScope::ConstPtr varType = m_typeResolver->varType(); const QQmlJSRegisterContent readType = m_typeResolver->canHoldUndefined(m_state.accumulatorIn()) ? property.storedIn(varType).castTo(varType) - : property; + : std::move(property); addReadAccumulator(readType); addReadRegister(base, callBase); m_state.setHasSideEffects(true); diff --git a/src/qmldom/qqmldomoutwriter.cpp b/src/qmldom/qqmldomoutwriter.cpp index bafd659e4b..b8e0fb5b47 100644 --- a/src/qmldom/qqmldomoutwriter.cpp +++ b/src/qmldom/qqmldomoutwriter.cpp @@ -290,13 +290,14 @@ DomItem OutWriter::restoreWrittenFileItem(const DomItem &fileItem) } } -DomItem OutWriter::writtenQmlFileItem(const DomItem &fileItem, Path filePath) +DomItem OutWriter::writtenQmlFileItem(const DomItem &fileItem, const Path &filePath) { Q_ASSERT(fileItem.internalKind() == DomType::QmlFile); auto mutableFile = fileItem.makeCopy(DomItem::CopyOption::EnvDisconnected); // QmlFile specific visitor for reformattedScriptExpressions tree // lambda function responsible for the update of the initial expression by the formatted one - auto exprUpdater = [&mutableFile, filePath](Path p, UpdatedScriptExpression::Tree t) { + auto exprUpdater = [&mutableFile, filePath]( + const Path &p, const UpdatedScriptExpression::Tree &t) { if (std::shared_ptr<ScriptExpression> formattedExpr = t->info().expr) { Q_ASSERT(p.mid(0, filePath.length()) == filePath); MutableDomItem originalExprItem = mutableFile.path(p.mid(filePath.length())); @@ -322,13 +323,13 @@ DomItem OutWriter::writtenQmlFileItem(const DomItem &fileItem, Path filePath) return mutableFile.item(); } -DomItem OutWriter::writtenJsFileItem(const DomItem &fileItem, Path filePath) +DomItem OutWriter::writtenJsFileItem(const DomItem &fileItem, const Path &filePath) { Q_ASSERT(fileItem.internalKind() == DomType::JsFile); auto mutableFile = fileItem.makeCopy(DomItem::CopyOption::EnvDisconnected); UpdatedScriptExpression::visitTree( reformattedScriptExpressions, - [&mutableFile, filePath](Path p, UpdatedScriptExpression::Tree t) { + [&mutableFile, filePath](const Path &p, const UpdatedScriptExpression::Tree &t) { if (std::shared_ptr<ScriptExpression> formattedExpr = t->info().expr) { Q_ASSERT(p.mid(0, filePath.length()) == filePath); mutableFile.mutableAs<JsFile>()->setExpression(formattedExpr); @@ -338,8 +339,9 @@ DomItem OutWriter::writtenJsFileItem(const DomItem &fileItem, Path filePath) return mutableFile.item(); } -void OutWriter::logScriptExprUpdateSkipped(DomItem exprItem, Path exprPath, - std::shared_ptr<ScriptExpression> formattedExpr) +void OutWriter::logScriptExprUpdateSkipped( + const DomItem &exprItem, const Path &exprPath, + const std::shared_ptr<ScriptExpression> &formattedExpr) { qCWarning(writeOutLog).noquote() << "Skipped update of reformatted ScriptExpression with " "code:\n---------------\n" diff --git a/src/qmldom/qqmldomoutwriter_p.h b/src/qmldom/qqmldomoutwriter_p.h index c79d07cf7d..8b00223ea2 100644 --- a/src/qmldom/qqmldomoutwriter_p.h +++ b/src/qmldom/qqmldomoutwriter_p.h @@ -150,10 +150,11 @@ public: DomItem restoreWrittenFileItem(const DomItem &fileItem); private: - DomItem writtenQmlFileItem(const DomItem &fileItem, Path filePath); - DomItem writtenJsFileItem(const DomItem &fileItem, Path filePath); - static void logScriptExprUpdateSkipped(DomItem exprItem, Path exprPath, - std::shared_ptr<ScriptExpression> formattedExpr); + DomItem writtenQmlFileItem(const DomItem &fileItem, const Path &filePath); + DomItem writtenJsFileItem(const DomItem &fileItem, const Path &filePath); + static void logScriptExprUpdateSkipped( + const DomItem &exprItem, const Path &exprPath, + const std::shared_ptr<ScriptExpression> &formattedExpr); }; } // end namespace Dom diff --git a/src/qmldom/qqmldomstringdumper_p.h b/src/qmldom/qqmldomstringdumper_p.h index 49f1763623..cf5c8e6483 100644 --- a/src/qmldom/qqmldomstringdumper_p.h +++ b/src/qmldom/qqmldomstringdumper_p.h @@ -63,7 +63,7 @@ public: Dumper(QStringView(string)) {} template <typename U, if_compatible_dumper<U> = true> - Dumper(U f): dumper(f) {} + Dumper(U f): dumper(std::move(f)) {} void operator()(const Sink &s) const { dumper(s); } }; diff --git a/src/qmldom/qqmldomtop.cpp b/src/qmldom/qqmldomtop.cpp index 7b4521da2a..05a1bc2d6f 100644 --- a/src/qmldom/qqmldomtop.cpp +++ b/src/qmldom/qqmldomtop.cpp @@ -293,7 +293,7 @@ DomUniverse::LoadResult DomUniverse::load(const ContentWithDate &codeWithDate, } else { Q_ASSERT(false); } - return { oldValue, newValue }; + return { std::move(oldValue), std::move(newValue) }; } /*! @@ -324,7 +324,7 @@ DomUniverse::PreloadResult DomUniverse::preload(const DomItem &univ, const FileT if (std::holds_alternative<ErrorMessage>(readResult)) { DomItem newValue; newValue.addError(std::move(std::get<ErrorMessage>(readResult))); - return LoadResult{ DomItem(), newValue }; // read failed, nothing to parse + return LoadResult{ DomItem(), std::move(newValue) }; // read failed, nothing to parse } else { codeWithDate = std::get<ContentWithDate>(readResult); } @@ -1247,7 +1247,8 @@ void DomEnvironment::loadFile(const FileToLoad &file, const Callback &loadCallba loadCallback(self.canonicalPath(), DomItem::empty, DomItem::empty); } if (endCallback) - addAllLoadedCallback(self, [p, endCallback](Path, const DomItem &, const DomItem &env) { + addAllLoadedCallback(self, [p = std::move(p), endCallback]( + const Path &, const DomItem &, const DomItem &env) { DomItem el = env.path(p); endCallback(p, el, el); }); diff --git a/src/qmldom/qqmldomtop_p.h b/src/qmldom/qqmldomtop_p.h index 410afa3b98..0462a1c380 100644 --- a/src/qmldom/qqmldomtop_p.h +++ b/src/qmldom/qqmldomtop_p.h @@ -412,7 +412,7 @@ private: curValue->currentExposedAt = now; if (curValue->current->isValid()) { curValue->valid = curValue->current; - curValue->validExposedAt = now; + curValue->validExposedAt = std::move(now); } newCurValue = curValue; } diff --git a/tools/qmlformat/qmlformat.cpp b/tools/qmlformat/qmlformat.cpp index e6dd518cb6..adaccb8d4a 100644 --- a/tools/qmlformat/qmlformat.cpp +++ b/tools/qmlformat/qmlformat.cpp @@ -158,7 +158,7 @@ static bool parseFile(const QString &filename, const Options &options) if (options.verbose) qWarning().noquote() << "Dumping" << filename; - const auto code = getFileItemOwner(fileItem)->code(); + const auto &code = getFileItemOwner(fileItem)->code(); auto lwOptions = composeLwOptions(options, code); WriteOutChecks checks = WriteOutCheck::Default; //Disable writeOutChecks for some usecases |