aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/corelib/buildgraph/inputartifactscanner.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2017-11-13 17:19:32 +0100
committerChristian Kandeler <christian.kandeler@qt.io>2017-11-30 16:12:55 +0000
commitc03f79f3af806cdec5c938d267486d338eaaab5d (patch)
tree763949fc5edda34de287a19d4a04461f588e3987 /src/lib/corelib/buildgraph/inputartifactscanner.cpp
parenta5cc49f2c62cfd4094c6a8bccd7741ca9ee7e072 (diff)
Remove as many dynamic_casts as possible
According to our benchmarker, this speeds up rule execution by three per cent. Change-Id: Iaf146ba6073b897d19e0fe470d7b0dc4a04d264c Reviewed-by: Jake Petroules <jake.petroules@qt.io>
Diffstat (limited to 'src/lib/corelib/buildgraph/inputartifactscanner.cpp')
-rw-r--r--src/lib/corelib/buildgraph/inputartifactscanner.cpp38
1 files changed, 28 insertions, 10 deletions
diff --git a/src/lib/corelib/buildgraph/inputartifactscanner.cpp b/src/lib/corelib/buildgraph/inputartifactscanner.cpp
index 13314eb52..177d1dfc8 100644
--- a/src/lib/corelib/buildgraph/inputartifactscanner.cpp
+++ b/src/lib/corelib/buildgraph/inputartifactscanner.cpp
@@ -79,14 +79,21 @@ static void resolveDepencency(const RawScannedDependency &dependency,
Artifact *dependencyInOtherProduct = nullptr;
for (FileResourceBase *lookupResult : project->topLevelProject()
->buildData->lookupFiles(absDirPath, dependency.fileName())) {
- if ((fileDependencyArtifact = dynamic_cast<FileDependency *>(lookupResult)))
- continue;
- Artifact * const foundArtifact = dynamic_cast<Artifact *>(lookupResult);
- if (foundArtifact->product == product) {
- dependencyInProduct = foundArtifact;
+ switch (lookupResult->fileType()) {
+ case FileResourceBase::FileTypeDependency:
+ fileDependencyArtifact = static_cast<FileDependency *>(lookupResult);
+ break;
+ case FileResourceBase::FileTypeArtifact: {
+ Artifact * const foundArtifact = static_cast<Artifact *>(lookupResult);
+ if (foundArtifact->product == product)
+ dependencyInProduct = foundArtifact;
+ else
+ dependencyInOtherProduct = foundArtifact;
break;
}
- dependencyInOtherProduct = foundArtifact;
+ }
+ if (dependencyInProduct)
+ break;
}
// prioritize found artifacts
@@ -266,8 +273,10 @@ unresolved:
resolved:
handleDependency(resolvedDependency);
if (artifactsToScan && resolvedDependency.file) {
- if (Artifact *artifactDependency = dynamic_cast<Artifact *>(resolvedDependency.file)) {
+ if (resolvedDependency.file->fileType() == FileResourceBase::FileTypeArtifact) {
// Do not scan an artifact that is not built yet: Its contents might still change.
+ Artifact * const artifactDependency
+ = static_cast<Artifact *>(resolvedDependency.file);
if (artifactDependency->artifactType == Artifact::SourceFile
|| artifactDependency->buildState == BuildGraphNode::Built) {
artifactsToScan->push_back(artifactDependency);
@@ -286,9 +295,18 @@ void InputArtifactScanner::handleDependency(ResolvedDependency &dependency)
QBS_CHECK(m_artifact->artifactType == Artifact::Generated);
QBS_CHECK(product);
- Artifact *artifactDependency = dynamic_cast<Artifact *>(dependency.file);
- FileDependency *fileDependency
- = artifactDependency ? 0 : dynamic_cast<FileDependency *>(dependency.file);
+ Artifact *artifactDependency = nullptr;
+ FileDependency *fileDependency = nullptr;
+ if (dependency.file) {
+ switch (dependency.file->fileType()) {
+ case FileResourceBase::FileTypeArtifact:
+ artifactDependency = static_cast<Artifact *>(dependency.file);
+ break;
+ case FileResourceBase::FileTypeDependency:
+ fileDependency = static_cast<FileDependency *>(dependency.file);
+ break;
+ }
+ }
QBS_CHECK(!dependency.file || artifactDependency || fileDependency);
if (!dependency.file) {