From c03f79f3af806cdec5c938d267486d338eaaab5d Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Mon, 13 Nov 2017 17:19:32 +0100 Subject: 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 --- .../corelib/buildgraph/inputartifactscanner.cpp | 38 ++++++++++++++++------ 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'src/lib/corelib/buildgraph/inputartifactscanner.cpp') 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(lookupResult))) - continue; - Artifact * const foundArtifact = dynamic_cast(lookupResult); - if (foundArtifact->product == product) { - dependencyInProduct = foundArtifact; + switch (lookupResult->fileType()) { + case FileResourceBase::FileTypeDependency: + fileDependencyArtifact = static_cast(lookupResult); + break; + case FileResourceBase::FileTypeArtifact: { + Artifact * const foundArtifact = static_cast(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(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(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(dependency.file); - FileDependency *fileDependency - = artifactDependency ? 0 : dynamic_cast(dependency.file); + Artifact *artifactDependency = nullptr; + FileDependency *fileDependency = nullptr; + if (dependency.file) { + switch (dependency.file->fileType()) { + case FileResourceBase::FileTypeArtifact: + artifactDependency = static_cast(dependency.file); + break; + case FileResourceBase::FileTypeDependency: + fileDependency = static_cast(dependency.file); + break; + } + } QBS_CHECK(!dependency.file || artifactDependency || fileDependency); if (!dependency.file) { -- cgit v1.2.3