FIR: Copy attributes when copying declaration
Otherwise they share FirDeclarationAttributes instance that might lead to problems when modifying only one of them
This commit is contained in:
@@ -10,6 +10,8 @@ sealed class ArrayMap<T : Any> : Iterable<T> {
|
||||
|
||||
abstract operator fun set(index: Int, value: T)
|
||||
abstract operator fun get(index: Int): T?
|
||||
|
||||
abstract fun copy(): ArrayMap<T>
|
||||
}
|
||||
|
||||
fun ArrayMap<*>.isEmpty(): Boolean = size == 0
|
||||
@@ -27,6 +29,8 @@ internal object EmptyArrayMap : ArrayMap<Nothing>() {
|
||||
return null
|
||||
}
|
||||
|
||||
override fun copy(): ArrayMap<Nothing> = this
|
||||
|
||||
override fun iterator(): Iterator<Nothing> {
|
||||
return object : Iterator<Nothing> {
|
||||
override fun hasNext(): Boolean = false
|
||||
@@ -48,6 +52,8 @@ internal class OneElementArrayMap<T : Any>(val value: T, val index: Int) : Array
|
||||
return if (index == this.index) value else null
|
||||
}
|
||||
|
||||
override fun copy(): ArrayMap<T> = OneElementArrayMap(value, index)
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
return object : Iterator<T> {
|
||||
private var notVisited = true
|
||||
@@ -68,16 +74,20 @@ internal class OneElementArrayMap<T : Any>(val value: T, val index: Int) : Array
|
||||
}
|
||||
}
|
||||
|
||||
internal class ArrayMapImpl<T : Any> : ArrayMap<T>() {
|
||||
internal class ArrayMapImpl<T : Any> private constructor(
|
||||
private var data: Array<Any?>
|
||||
) : ArrayMap<T>() {
|
||||
companion object {
|
||||
private const val DEFAULT_SIZE = 20
|
||||
private const val INCREASE_K = 2
|
||||
}
|
||||
|
||||
constructor() : this(arrayOfNulls<Any>(DEFAULT_SIZE))
|
||||
|
||||
override var size: Int = 0
|
||||
private set
|
||||
|
||||
private var data = arrayOfNulls<Any>(DEFAULT_SIZE)
|
||||
|
||||
private fun ensureCapacity(index: Int) {
|
||||
if (data.size <= index) {
|
||||
data = data.copyOf(data.size * INCREASE_K)
|
||||
@@ -97,6 +107,8 @@ internal class ArrayMapImpl<T : Any> : ArrayMap<T>() {
|
||||
return data.getOrNull(index) as T?
|
||||
}
|
||||
|
||||
override fun copy(): ArrayMap<T> = ArrayMapImpl(data.copyOf())
|
||||
|
||||
override fun iterator(): Iterator<T> {
|
||||
return object : AbstractIterator<T>() {
|
||||
private var index = -1
|
||||
@@ -128,4 +140,4 @@ internal class ArrayMapImpl<T : Any> : ArrayMap<T>() {
|
||||
}
|
||||
|
||||
data class Entry<T>(override val key: Int, override val value: T) : Map.Entry<Int, T>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,11 +17,15 @@ import kotlin.reflect.KClass
|
||||
* from components in [ComponentArrayOwner]
|
||||
*/
|
||||
@OptIn(Protected::class)
|
||||
abstract class AttributeArrayOwner<K : Any, T : Any> : AbstractArrayMapOwner<K, T>() {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
final override var arrayMap: ArrayMap<T> = EmptyArrayMap as ArrayMap<T>
|
||||
abstract class AttributeArrayOwner<K : Any, T : Any> protected constructor(
|
||||
arrayMap: ArrayMap<T>
|
||||
) : AbstractArrayMapOwner<K, T>() {
|
||||
final override var arrayMap: ArrayMap<T> = arrayMap
|
||||
private set
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
constructor() : this(EmptyArrayMap as ArrayMap<T>)
|
||||
|
||||
final override fun registerComponent(tClass: KClass<out K>, value: T) {
|
||||
val id = typeRegistry.getId(tClass)
|
||||
when (arrayMap.size) {
|
||||
@@ -61,4 +65,4 @@ abstract class AttributeArrayOwner<K : Any, T : Any> : AbstractArrayMapOwner<K,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user