forked from qt-creator/qt-creator
Optimize addTargets() method
Don't lookup for matching targetDetails on every iteration. Before we start a loop we prepare the appropriate hash and use it on every iteration instead. This shortens the total time spent on findOrDefault from about 2 seconds to about 10 miliseconds now. Change-Id: I89bb3f472bc9071a54f9900fa057f87b57d4742d Reviewed-by: Cristian Adam <cristian.adam@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -595,9 +595,20 @@ void addTargets(const QHash<Utils::FilePath, ProjectExplorer::ProjectNode *> &cm
|
||||
const FilePath &sourceDir,
|
||||
const FilePath &buildDir)
|
||||
{
|
||||
QHash<QString, const TargetDetails *> targetDetailsHash;
|
||||
for (const TargetDetails &t : targetDetails)
|
||||
targetDetailsHash.insert(t.id, &t);
|
||||
const TargetDetails defaultTargetDetails;
|
||||
auto getTargetDetails = [&targetDetailsHash, &defaultTargetDetails](const QString &id)
|
||||
-> const TargetDetails & {
|
||||
auto it = targetDetailsHash.constFind(id);
|
||||
if (it != targetDetailsHash.constEnd())
|
||||
return *it.value();
|
||||
return defaultTargetDetails;
|
||||
};
|
||||
|
||||
for (const FileApiDetails::Target &t : config.targets) {
|
||||
const TargetDetails &td = Utils::findOrDefault(targetDetails,
|
||||
Utils::equal(&TargetDetails::id, t.id));
|
||||
const TargetDetails &td = getTargetDetails(t.id);
|
||||
|
||||
const FilePath dir = directorySourceDir(config, sourceDir, t.directory);
|
||||
|
||||
|
Reference in New Issue
Block a user