forked from qt-creator/qt-creator
QmlJS: Reduce number of for loops
Removes some unnecessary contains() by using the QSet directly. Fetch all required paths at once instead of calling generatedQrc(...) multiple times. Change-Id: I0a6f65d11d92a4ec4f6655a87e30df6a5c4d6545 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -449,13 +449,18 @@ bool pInfoLessThanImports(const ModelManagerInterface::ProjectInfo &p1,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline void combine(QSet<FilePath> &set, const QList<FilePath> &list)
|
||||||
|
{
|
||||||
|
for (const FilePath &path : list)
|
||||||
|
set.insert(path);
|
||||||
|
}
|
||||||
|
|
||||||
static QSet<Utils::FilePath> generatedQrc(
|
static QSet<Utils::FilePath> generatedQrc(
|
||||||
const QList<ModelManagerInterface::ProjectInfo> &projectInfos)
|
const QList<ModelManagerInterface::ProjectInfo> &projectInfos)
|
||||||
{
|
{
|
||||||
QSet<Utils::FilePath> res;
|
QSet<Utils::FilePath> res;
|
||||||
for (const auto &pInfo : projectInfos) {
|
for (const auto &pInfo : projectInfos) {
|
||||||
for (const auto &generatedQrcFile: pInfo.generatedQrcFiles)
|
combine(res, pInfo.generatedQrcFiles);
|
||||||
res.insert(generatedQrcFile);
|
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
@@ -475,25 +480,21 @@ void ModelManagerInterface::iterateQrcFiles(
|
|||||||
Utils::sort(pInfos, &pInfoLessThanAll);
|
Utils::sort(pInfos, &pInfoLessThanAll);
|
||||||
}
|
}
|
||||||
|
|
||||||
QSet<Utils::FilePath> pathsChecked;
|
QSet<Utils::FilePath> allQrcs = generatedQrc(pInfos);
|
||||||
|
|
||||||
for (const ModelManagerInterface::ProjectInfo &pInfo : std::as_const(pInfos)) {
|
for (const ModelManagerInterface::ProjectInfo &pInfo : std::as_const(pInfos)) {
|
||||||
QList<Utils::FilePath> qrcFilePaths;
|
|
||||||
if (resources == ActiveQrcResources)
|
if (resources == ActiveQrcResources)
|
||||||
qrcFilePaths = pInfo.activeResourceFiles;
|
combine(allQrcs, pInfo.activeResourceFiles);
|
||||||
else
|
else
|
||||||
qrcFilePaths = pInfo.allResourceFiles;
|
combine(allQrcs, pInfo.allResourceFiles);
|
||||||
for (const Utils::FilePath &p : generatedQrc({pInfo}))
|
}
|
||||||
qrcFilePaths.append(p);
|
|
||||||
for (const Utils::FilePath &qrcFilePath : std::as_const(qrcFilePaths)) {
|
for (const Utils::FilePath &qrcFilePath : std::as_const(allQrcs)) {
|
||||||
if (pathsChecked.contains(qrcFilePath))
|
QrcParser::ConstPtr qrcFile = m_qrcCache.parsedPath(qrcFilePath.toFSPathString());
|
||||||
continue;
|
|
||||||
pathsChecked.insert(qrcFilePath);
|
|
||||||
QrcParser::ConstPtr qrcFile = m_qrcCache.parsedPath(qrcFilePath.toString());
|
|
||||||
if (qrcFile.isNull())
|
if (qrcFile.isNull())
|
||||||
continue;
|
continue;
|
||||||
callback(qrcFile);
|
callback(qrcFile);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList ModelManagerInterface::qrcPathsForFile(const Utils::FilePath &file,
|
QStringList ModelManagerInterface::qrcPathsForFile(const Utils::FilePath &file,
|
||||||
|
|||||||
Reference in New Issue
Block a user