Skip to content

Commit 676b6f5

Browse files
committed
refactor(analyzer): Simplify getModuleInfo()
The reason why a `Map` is used is for better performance in the caller logic. So, creating that map better fits into the caller. The function now also aligns better with its KDoc. Signed-off-by: Frank Viernau <[email protected]>
1 parent 31bdf3f commit 676b6f5

File tree

1 file changed

+3
-5
lines changed
  • analyzer/src/main/kotlin/managers

1 file changed

+3
-5
lines changed

analyzer/src/main/kotlin/managers/GoMod.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class GoMod(
117117
val projectDir = definitionFile.parentFile
118118

119119
stashDirectories(projectDir.resolve("vendor")).use { _ ->
120-
val moduleInfoForModuleName = getModuleInfos(projectDir)
120+
val moduleInfoForModuleName = getModuleInfos(projectDir).associateBy { it.path }
121121
val graph = getModuleGraph(projectDir, moduleInfoForModuleName)
122122
val packages = graph.nodes.mapNotNullTo(mutableSetOf()) {
123123
moduleInfoForModuleName.getValue(it.name).toPackage()
@@ -262,12 +262,10 @@ class GoMod(
262262
* Return the list of all modules contained in the dependency tree with resolved versions and the 'replace'
263263
* directive applied.
264264
*/
265-
private fun getModuleInfos(projectDir: File): Map<String, ModuleInfo> {
265+
private fun getModuleInfos(projectDir: File): List<ModuleInfo> {
266266
val list = runGo("list", "-m", "-json", "-buildvcs=false", "all", workingDir = projectDir)
267267

268-
val moduleInfos = list.stdout.byteInputStream().use { JSON.decodeToSequence<ModuleInfo>(it) }
269-
270-
return moduleInfos.associateBy { it.path }
268+
return list.stdout.byteInputStream().use { JSON.decodeToSequence<ModuleInfo>(it) }.toList()
271269
}
272270

273271
/**

0 commit comments

Comments
 (0)