[SLC] introduce SimpleModifiersBox

^KT-56046
This commit is contained in:
Dmitrii Gridin
2023-01-24 20:09:26 +01:00
committed by Space Team
parent c401cd3210
commit eaf6798684
3 changed files with 22 additions and 2 deletions
@@ -24,10 +24,10 @@ internal typealias LazyModifiersComputer = (modifier: String) -> Map<String, Boo
internal class LazyModifiersBox(
initialValue: Map<String, Boolean>,
private val computer: LazyModifiersComputer,
) {
) : ModifiersBox {
private val modifiersMapReference: AtomicReference<PersistentMap<String, Boolean>> = AtomicReference(initialValue.toPersistentHashMap())
fun hasModifier(modifier: String): Boolean {
override fun hasModifier(modifier: String): Boolean {
modifiersMapReference.get()[modifier]?.let { return it }
val newValues = computer(modifier) ?: mapOf(modifier to false)
modifiersMapReference.updateAndGet {
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.light.classes.symbol.modifierLists
internal sealed interface ModifiersBox {
fun hasModifier(modifier: String): Boolean
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.light.classes.symbol.modifierLists
internal class SimpleModifiersBox(private val modifiers: Set<String>) : ModifiersBox {
override fun hasModifier(modifier: String): Boolean = modifier in modifiers
}