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>
This commit is contained in:
Ulf Hermann 2024-01-29 13:50:32 +01:00
parent 7d2eecea4f
commit 66af11c6cb
7 changed files with 21 additions and 17 deletions

View File

@ -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);

View File

@ -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"

View File

@ -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

View File

@ -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); }
};

View File

@ -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);
});

View File

@ -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;
}

View File

@ -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