[Workspace Model] [IDEA-348672] Use concurrent hash map to store the information about the unloaded modules

Generally, it seems like this can be rewritten to just use the unloaded storage and do not store the additional information in maps.
This change is intended to fix the concurrency issue.

With the change of the map, we loose the ordering of the keys. The ordering, however, doesn't matter. It's only exposed via `allModuleDescriptions` and `unloadedModuleDescriptions` functions, but they have a `Collection` type that doesn't specify the ordering. Also, in practice, the ordering is not used not by intellij, nor by external plugins code.

The map of modules was original unordered and ordering was added in 5f7c407aae45df034a3dc1c0a9876a53807b64b8 without any specific reason for that.

GitOrigin-RevId: 8e3f0a25fc14e1315127cca88d7658bd7d6e5d59
This commit is contained in:
Alex Plate
2024-07-17 16:53:17 +03:00
committed by intellij-monorepo-bot
parent 4e3dfb7d67
commit c24d7c1b7a

View File

@@ -55,6 +55,7 @@ import kotlinx.coroutines.*
import org.jetbrains.annotations.ApiStatus
import java.nio.file.Path
import java.util.*
import java.util.concurrent.ConcurrentHashMap
private val loadAllModulesTimeMs = MillisecondsMeasurer()
@@ -82,7 +83,7 @@ internal class ModuleManagerComponentBridgeInitializer : BridgeInitializer {
abstract class ModuleManagerBridgeImpl(private val project: Project,
private val coroutineScope: CoroutineScope,
moduleRootListenerBridge: ModuleRootListenerBridge) : ModuleManagerEx(), Disposable {
private val moduleNameToUnloadedModuleDescription: MutableMap<String, UnloadedModuleDescription> = LinkedHashMap()
private val moduleNameToUnloadedModuleDescription: MutableMap<String, UnloadedModuleDescription> = ConcurrentHashMap()
private val moduleNamesQuery = entities<ModuleEntity>().map { it.name }