From 615ae0a2da9f67f0c8eea397264330182fd2e867 Mon Sep 17 00:00:00 2001 From: Sebastian Schuberth Date: Mon, 15 Apr 2024 18:18:38 +0200 Subject: [PATCH] perf(GenerateScopeExcludesCommand): Deduplicate scopes into sets This also avoids logging the same scope multiple times. Signed-off-by: Sebastian Schuberth --- .../kotlin/commands/repoconfig/GenerateScopeExcludesCommand.kt | 2 +- .../src/main/kotlin/commands/repoconfig/RemoveEntriesCommand.kt | 2 +- helper-cli/src/main/kotlin/utils/Extensions.kt | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/helper-cli/src/main/kotlin/commands/repoconfig/GenerateScopeExcludesCommand.kt b/helper-cli/src/main/kotlin/commands/repoconfig/GenerateScopeExcludesCommand.kt index 24ae990d65bba..510c692bc5e5f 100644 --- a/helper-cli/src/main/kotlin/commands/repoconfig/GenerateScopeExcludesCommand.kt +++ b/helper-cli/src/main/kotlin/commands/repoconfig/GenerateScopeExcludesCommand.kt @@ -77,7 +77,7 @@ internal class GenerateScopeExcludesCommand : CliktCommand( } private fun OrtResult.generateScopeExcludes(): List { - val projectScopes = getProjects().flatMap { project -> + val projectScopes = getProjects().flatMapTo(mutableSetOf()) { project -> dependencyNavigator.scopeNames(project) } diff --git a/helper-cli/src/main/kotlin/commands/repoconfig/RemoveEntriesCommand.kt b/helper-cli/src/main/kotlin/commands/repoconfig/RemoveEntriesCommand.kt index f1b01fbc7f703..5254b03861b34 100644 --- a/helper-cli/src/main/kotlin/commands/repoconfig/RemoveEntriesCommand.kt +++ b/helper-cli/src/main/kotlin/commands/repoconfig/RemoveEntriesCommand.kt @@ -94,7 +94,7 @@ internal class RemoveEntriesCommand : CliktCommand( val scopeExcludes = ortResult .getProjects() - .flatMap { project -> project.scopes.map { scope -> scope.name } } + .flatMapTo(mutableSetOf()) { project -> project.scopes.map { scope -> scope.name } } .let { projectScopes -> ortResult.getExcludes().scopes.minimize(projectScopes) } val licenseFindings = ortResult.getProjectLicenseFindings() diff --git a/helper-cli/src/main/kotlin/utils/Extensions.kt b/helper-cli/src/main/kotlin/utils/Extensions.kt index 006784703bd1f..1887319336f86 100644 --- a/helper-cli/src/main/kotlin/utils/Extensions.kt +++ b/helper-cli/src/main/kotlin/utils/Extensions.kt @@ -79,7 +79,7 @@ import org.ossreviewtoolkit.utils.spdx.SpdxSingleLicenseExpression * Return an approximated minimal sublist of [this] so that the result still matches the exact same entries of the given * [projectScopes]. */ -internal fun List.minimize(projectScopes: List): List { +internal fun List.minimize(projectScopes: Set): List { val scopeExcludes = associateWith { scopeExclude -> projectScopes.filter { scopeExclude.matches(it) }.toSet() }