Skip to content

Commit

Permalink
Use single map for both packages and moduleFor calculations, whic…
Browse files Browse the repository at this point in the history
…h are heavily used by `DefaultExternalLocationProvider.resolve` (#4009)
  • Loading branch information
whyoleg authored Jan 30, 2025
1 parent af87c48 commit 961c677
Showing 1 changed file with 13 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,21 @@ public data class PackageList(
val locations: Map<String, String>,
val url: URL
) {
val packages: Set<String>
get() = modules.values.flatten().toSet()

public fun moduleFor(packageName: String): Module? {
return modules.asSequence()
.filter { it.value.contains(packageName) }
.firstOrNull()?.key
private val moduleByPackage: Map<String, Module> by lazy {
mutableMapOf<String, Module>().apply {
modules.forEach { (module, packages) ->
packages.forEach { pkg ->
// if multiple modules have the same package (split-package), store the first module.
if (!containsKey(pkg)) put(pkg, module)
}
}
}
}

val packages: Set<String> get() = moduleByPackage.keys

public fun moduleFor(packageName: String): Module? = moduleByPackage[packageName]

public companion object {
public const val PACKAGE_LIST_NAME: String = "package-list"
public const val MODULE_DELIMITER: String = "module:"
Expand Down

0 comments on commit 961c677

Please sign in to comment.