Skip to content

Commit

Permalink
Merge pull request #1640 from KAMO030/main
Browse files Browse the repository at this point in the history
perf The module flattening function can reduce GC using MutableSet
  • Loading branch information
arnaudgiuliani authored Sep 7, 2023
2 parents 280fdfe + 656cb48 commit 7cd52f0
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -235,16 +235,12 @@ operator fun List<Module>.plus(module: Module): List<Module> = this + listOf(mod
* Run through the module list to flatten all modules & submodules
*/
@OptIn(KoinInternalApi::class)
tailrec fun flatten(modules: List<Module>, newModules: Set<Module> = emptySet()): Set<Module> {
return if (modules.isEmpty()) {
newModules
} else {
val head = modules.first()
val tail = modules.subList(1, modules.size)
if (head.includedModules.isEmpty()) {
flatten(tail, newModules + head)
} else {
flatten(head.includedModules + tail, newModules + head)
fun flatten(modules: List<Module>): Set<Module> {
fun flat(modules: List<Module>, newModules: MutableSet<Module>){
modules.forEach{
newModules += it
flat(it.includedModules,newModules)
}
}
return mutableSetOf<Module>().apply { flat(modules,this) }
}

0 comments on commit 7cd52f0

Please sign in to comment.