Skip to content

Commit

Permalink
perf(GenerateScopeExcludesCommand): Deduplicate scopes into sets
Browse files Browse the repository at this point in the history
This also avoids logging the same scope multiple times.

Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
  • Loading branch information
sschuberth committed Apr 15, 2024
1 parent 50069be commit 615ae0a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ internal class GenerateScopeExcludesCommand : CliktCommand(
}

private fun OrtResult.generateScopeExcludes(): List<ScopeExclude> {
val projectScopes = getProjects().flatMap { project ->
val projectScopes = getProjects().flatMapTo(mutableSetOf()) { project ->
dependencyNavigator.scopeNames(project)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion helper-cli/src/main/kotlin/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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<ScopeExclude>.minimize(projectScopes: List<String>): List<ScopeExclude> {
internal fun List<ScopeExclude>.minimize(projectScopes: Set<String>): List<ScopeExclude> {
val scopeExcludes = associateWith { scopeExclude ->
projectScopes.filter { scopeExclude.matches(it) }.toSet()
}
Expand Down

0 comments on commit 615ae0a

Please sign in to comment.