diff options
author | Ivan Komissarov <abbapoh@gmail.com> | 2020-05-14 18:49:05 +0200 |
---|---|---|
committer | Ivan Komissarov <ABBAPOH@gmail.com> | 2020-05-25 08:59:04 +0000 |
commit | ff61ba1702644bd558ba5d65821b885d39a21e1d (patch) | |
tree | 3938f243e9126bf1163cce06264ca46b02132ebf /src | |
parent | 6bba36e5e76820409bd3afad5da6883a79f79904 (diff) | |
download | qbs-ff61ba1702644bd558ba5d65821b885d39a21e1d.tar.gz |
ProjectData: return const values/references
Qbs does not care that much about binary compatilibity (because of qbs
session) and thus is is preferable to return members by const-ref
(saving 2 atomic operations and preventing from accidental detaches). In
case when method needs to compute some value instead of returning member
directly, the function signature can be changed.
Change-Id: I4e8d228761a990d274e77652c94adf9f43a758f1
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/app/qbs/commandlinefrontend.cpp | 9 | ||||
-rw-r--r-- | src/app/qbs/status.cpp | 3 | ||||
-rw-r--r-- | src/lib/corelib/api/project.cpp | 9 | ||||
-rw-r--r-- | src/lib/corelib/api/projectdata.cpp | 14 | ||||
-rw-r--r-- | src/lib/corelib/api/projectdata.h | 14 | ||||
-rw-r--r-- | src/plugins/generator/clangcompilationdb/clangcompilationdbgenerator.cpp | 5 | ||||
-rw-r--r-- | src/plugins/generator/makefilegenerator/makefilegenerator.cpp | 4 |
7 files changed, 25 insertions, 33 deletions
diff --git a/src/app/qbs/commandlinefrontend.cpp b/src/app/qbs/commandlinefrontend.cpp index d8b4d9ca8..4a28b93ec 100644 --- a/src/app/qbs/commandlinefrontend.cpp +++ b/src/app/qbs/commandlinefrontend.cpp @@ -351,8 +351,7 @@ CommandLineFrontend::ProductMap CommandLineFrontend::productsToUse() const for (const Project &project : qAsConst(m_projects)) { QList<ProductData> &productList = products[project]; const ProjectData projectData = project.projectData(); - const auto products = projectData.allProducts(); - for (const ProductData &product : products) { + for (const ProductData &product : projectData.allProducts()) { productNames << product.name(); if (useAll || m_parser.products().contains(product.name())) { productList.push_back(product); @@ -647,8 +646,7 @@ ProductData CommandLineFrontend::getTheOneRunnableProduct() QBS_CHECK(m_projects.size() == 1); // Has been checked earlier. if (m_parser.products().size() == 1) { - const auto products = m_projects.front().projectData().allProducts(); - for (const ProductData &p : products) { + for (const ProductData &p : m_projects.front().projectData().allProducts()) { if (p.name() == m_parser.products().constFirst()) return p; } @@ -657,8 +655,7 @@ ProductData CommandLineFrontend::getTheOneRunnableProduct() QBS_CHECK(m_parser.products().isEmpty()); QList<ProductData> runnableProducts; - const auto products = m_projects.front().projectData().allProducts(); - for (const ProductData &p : products) { + for (const ProductData &p : m_projects.front().projectData().allProducts()) { if (p.isRunnable()) runnableProducts.push_back(p); } diff --git a/src/app/qbs/status.cpp b/src/app/qbs/status.cpp index 3dc540ff5..2efc6e36a 100644 --- a/src/app/qbs/status.cpp +++ b/src/app/qbs/status.cpp @@ -134,8 +134,7 @@ int printStatus(const ProjectData &project) QStringList untrackedFilesInProject = allFilesInProject(projectDirectory); QStringList missingFiles; - const auto products = project.allProducts(); - for (const ProductData &product : products) { + for (const ProductData &product : project.allProducts()) { qbsInfo() << "\nProduct: " << product.name() << " (" << product.location().filePath() << ":" << product.location().line() << ")"; diff --git a/src/lib/corelib/api/project.cpp b/src/lib/corelib/api/project.cpp index 2b07f1a8d..c7b6e99e7 100644 --- a/src/lib/corelib/api/project.cpp +++ b/src/lib/corelib/api/project.cpp @@ -234,8 +234,7 @@ ResolvedProductPtr ProjectPrivate::internalProduct(const ProductData &product) c ProductData ProjectPrivate::findProductData(const ProductData &product) const { - const auto products = m_projectData.allProducts(); - for (const ProductData &p : products) { + for (const ProductData &p : m_projectData.allProducts()) { if (p.name() == product.name() && p.profile() == product.profile() && p.multiplexConfigurationId() == product.multiplexConfigurationId()) { @@ -248,8 +247,7 @@ ProductData ProjectPrivate::findProductData(const ProductData &product) const QList<ProductData> ProjectPrivate::findProductsByName(const QString &name) const { QList<ProductData> list; - const auto products = m_projectData.allProducts(); - for (const ProductData &p : products) { + for (const ProductData &p : m_projectData.allProducts()) { if (p.name() == name) list.push_back(p); } @@ -596,8 +594,7 @@ ProjectTransformerData ProjectPrivate::transformerData() if (!m_projectData.isValid()) retrieveProjectData(m_projectData, internalProject); ProjectTransformerData projectTransformerData; - const auto allProducts = m_projectData.allProducts(); - for (const ProductData &productData : allProducts) { + for (const ProductData &productData : m_projectData.allProducts()) { if (!productData.isEnabled()) continue; const ResolvedProductConstPtr product = internalProduct(productData); diff --git a/src/lib/corelib/api/projectdata.cpp b/src/lib/corelib/api/projectdata.cpp index 7c64bf6ff..f15dd63a2 100644 --- a/src/lib/corelib/api/projectdata.cpp +++ b/src/lib/corelib/api/projectdata.cpp @@ -812,7 +812,7 @@ QJsonObject ProjectData::toJson(const QStringList &moduleProperties) const /*! * \brief The name of this project. */ -QString ProjectData::name() const +const QString &ProjectData::name() const { return d->name; } @@ -820,7 +820,7 @@ QString ProjectData::name() const /*! * \brief The location at which the project is defined in a qbs source file. */ -CodeLocation ProjectData::location() const +const CodeLocation &ProjectData::location() const { return d->location; } @@ -839,7 +839,7 @@ bool ProjectData::isEnabled() const * \brief The base directory under which the build artifacts of this project will be created. * This is only valid for the top-level project. */ -QString ProjectData::buildDirectory() const +const QString &ProjectData::buildDirectory() const { return d->buildDir; } @@ -848,7 +848,7 @@ QString ProjectData::buildDirectory() const * The products in this project. * \note This also includes disabled products. */ -QList<ProductData> ProjectData::products() const +const QList<ProductData> &ProjectData::products() const { return d->products; } @@ -856,7 +856,7 @@ QList<ProductData> ProjectData::products() const /*! * The sub-projects of this project. */ -QList<ProjectData> ProjectData::subProjects() const +const QList<ProjectData> &ProjectData::subProjects() const { return d->subProjects; } @@ -864,7 +864,7 @@ QList<ProjectData> ProjectData::subProjects() const /*! * All products in this projects and its direct and indirect sub-projects. */ -QList<ProductData> ProjectData::allProducts() const +const QList<ProductData> ProjectData::allProducts() const { QList<ProductData> productList = products(); for (const ProjectData &pd : qAsConst(d->subProjects)) @@ -875,7 +875,7 @@ QList<ProductData> ProjectData::allProducts() const /*! * The artifacts of all products in this project that are to be installed. */ -QList<ArtifactData> ProjectData::installableArtifacts() const +const QList<ArtifactData> ProjectData::installableArtifacts() const { QList<ArtifactData> artifacts; const auto products = allProducts(); diff --git a/src/lib/corelib/api/projectdata.h b/src/lib/corelib/api/projectdata.h index a285f8570..2e6785010 100644 --- a/src/lib/corelib/api/projectdata.h +++ b/src/lib/corelib/api/projectdata.h @@ -241,14 +241,14 @@ public: bool isValid() const; QJsonObject toJson(const QStringList &moduleProperties = {}) const; - QString name() const; - CodeLocation location() const; + const QString &name() const; + const CodeLocation &location() const; bool isEnabled() const; - QString buildDirectory() const; - QList<ProductData> products() const; - QList<ProjectData> subProjects() const; - QList<ProductData> allProducts() const; - QList<ArtifactData> installableArtifacts() const; + const QString &buildDirectory() const; + const QList<ProductData> &products() const; + const QList<ProjectData> &subProjects() const; + const QList<ProductData> allProducts() const; + const QList<ArtifactData> installableArtifacts() const; private: QExplicitlySharedDataPointer<Internal::ProjectDataPrivate> d; diff --git a/src/plugins/generator/clangcompilationdb/clangcompilationdbgenerator.cpp b/src/plugins/generator/clangcompilationdb/clangcompilationdbgenerator.cpp index 93be2804b..d73cd49a6 100644 --- a/src/plugins/generator/clangcompilationdb/clangcompilationdbgenerator.cpp +++ b/src/plugins/generator/clangcompilationdb/clangcompilationdbgenerator.cpp @@ -71,10 +71,9 @@ void ClangCompilationDatabaseGenerator::generate() for (const Project &theProject : projects) { QJsonArray database; const ProjectData projectData = theProject.projectData(); - const QString buildDir = projectData.buildDirectory(); + const QString &buildDir = projectData.buildDirectory(); - const auto products = projectData.allProducts(); - for (const ProductData &productData : products) { + for (const ProductData &productData : projectData.allProducts()) { const auto groups = productData.groups(); for (const GroupData &groupData : groups) { const auto sourceArtifacts = groupData.allSourceArtifacts(); diff --git a/src/plugins/generator/makefilegenerator/makefilegenerator.cpp b/src/plugins/generator/makefilegenerator/makefilegenerator.cpp index 24aff5a33..a158df0ac 100644 --- a/src/plugins/generator/makefilegenerator/makefilegenerator.cpp +++ b/src/plugins/generator/makefilegenerator/makefilegenerator.cpp @@ -182,7 +182,7 @@ void qbs::MakefileGenerator::generate() "is not supported by this generator.").arg(srcDir)); } stream << "SRCDIR = " << QDir::toNativeSeparators(srcDir) << '\n'; - const QString buildDir = projectData.buildDirectory(); + const QString &buildDir = projectData.buildDirectory(); if (buildDir.contains(QLatin1Char(' '))) { throw ErrorInfo(Tr::tr("The build directory '%1' contains space characters, which" "is not supported by this generator.").arg(buildDir)); @@ -293,7 +293,7 @@ void qbs::MakefileGenerator::generate() stream << "install-" << productTarget << ": " << productTarget << '\n'; Set<QString> createdDirs; const auto installableArtifacts = productData.installableArtifacts(); - for (const ArtifactData &artifact : installableArtifacts) { + for (const ArtifactData &artifact : productData.installableArtifacts()) { const QString &outputDir = artifact.installData().localInstallDir(); if (outputDir.contains(QLatin1Char(' '))) { logger().qbsWarning() << Tr::tr("Skipping installation of '%1', because " |