Skip to content

Commit ec592fb

Browse files
committed
Use an efficient BFS for resolving libraries.
^KT-80722
1 parent 4b88edb commit ec592fb

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

compiler/util-klib-metadata/src/org/jetbrains/kotlin/library/metadata/resolver/impl/KotlinLibraryResolverImpl.kt

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -129,28 +129,24 @@ class KotlinLibraryResolverImpl<L : KotlinLibrary> internal constructor(
129129
val cache = mutableMapOf<Any, KotlinResolvedLibrary>()
130130
cache.putAll(rootLibraries.map { it.library.libraryFile.fileKey to it })
131131

132-
var newDependencies = rootLibraries
133-
do {
134-
newDependencies = newDependencies.map { library: KotlinResolvedLibraryImpl ->
135-
library.library.unresolvedDependencies(resolveManifestDependenciesLenient).asSequence()
136-
137-
.filterNot { searchPathResolver.isProvidedByDefault(it) }
138-
.mapNotNull { searchPathResolver.resolve(it)?.let(::KotlinResolvedLibraryImpl) }
139-
.map { resolved ->
140-
val fileKey = resolved.library.libraryFile.fileKey
141-
if (fileKey in cache) {
142-
library.addDependency(cache[fileKey]!!)
143-
null
144-
} else {
145-
cache.put(fileKey, resolved)
146-
library.addDependency(resolved)
147-
resolved
148-
}
149-
150-
}.filterNotNull()
151-
.toList()
152-
}.flatten()
153-
} while (newDependencies.isNotEmpty())
132+
val processingQueue = ArrayDeque(rootLibraries)
133+
while(processingQueue.isNotEmpty()) {
134+
val currentLibrary = processingQueue.removeFirst()
135+
currentLibrary.library.unresolvedDependencies(resolveManifestDependenciesLenient).asSequence()
136+
.filterNot { searchPathResolver.isProvidedByDefault(it) }
137+
.mapNotNull { searchPathResolver.resolve(it) }
138+
.forEach { resolvedDependencyLibrary ->
139+
val fileKey = resolvedDependencyLibrary.libraryFile.fileKey
140+
if (fileKey in cache) {
141+
currentLibrary.addDependency(cache[fileKey]!!)
142+
} else {
143+
val newlyResolved = KotlinResolvedLibraryImpl(resolvedDependencyLibrary)
144+
cache[fileKey] = newlyResolved
145+
currentLibrary.addDependency(newlyResolved)
146+
processingQueue.add(newlyResolved)
147+
}
148+
}
149+
}
154150
return result
155151
}
156152
}

0 commit comments

Comments
 (0)