From fc77b60658d14b5a62d533ffbfd6c038e48bd23f Mon Sep 17 00:00:00 2001 From: Dmitry Kichinsky Date: Thu, 28 Nov 2024 22:14:48 +0100 Subject: [PATCH] [amper] AMPER-544 update cached compilerArguments if changed in workspace model GitOrigin-RevId: c3520c618f0eda983035fed387732a8351955be5 --- .../KotlinFacetSettingsWorkspaceModel.kt | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt index 4bb6398dc08c..37b103d6da45 100644 --- a/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt +++ b/plugins/kotlin/base/facet/src/org/jetbrains/kotlin/idea/serialization/KotlinFacetSettingsWorkspaceModel.kt @@ -49,23 +49,29 @@ class KotlinFacetSettingsWorkspaceModel(val entity: KotlinSettingsEntity.Builder } private var _compilerArguments: CommonCompilerArguments? = null + private var _lastKnownCompilerArguments: String? = null override var compilerArguments: CommonCompilerArguments? get() { - if (_compilerArguments != null) { + val currentSerializedArguments = entity.compilerArguments + if (_compilerArguments != null && currentSerializedArguments == _lastKnownCompilerArguments) { + // Cache is valid, return the cached value return _compilerArguments } - val serializedArguments = entity.compilerArguments - _compilerArguments = serializedArguments?.let { + // Deserialize and update the cache + _compilerArguments = currentSerializedArguments?.let { CompilerArgumentsSerializer.deserializeFromString(it) } + _lastKnownCompilerArguments = currentSerializedArguments return _compilerArguments } set(value) { - entity.compilerArguments = CompilerArgumentsSerializer.serializeToString(value) + val serializedValue = CompilerArgumentsSerializer.serializeToString(value) + entity.compilerArguments = serializedValue updateMergedArguments() _compilerArguments = value?.unfrozen() + _lastKnownCompilerArguments = serializedValue } override val mergedCompilerArguments: CommonCompilerArguments?