@@ -26,7 +26,7 @@ abstract class IrElementBase : IrElement {
26
26
* Keys are of type [IrAttribute].
27
27
* Values are arbitrary objects but cannot be null.
28
28
*/
29
- private var attributeMap : Array <Any ?>? = null
29
+ private var _attributes : Array <Any ?>? = null
30
30
31
31
override fun <D > transform (transformer : IrTransformer <D >, data : D ): IrElement =
32
32
accept(transformer, data)
@@ -44,15 +44,15 @@ abstract class IrElementBase : IrElement {
44
44
* Returns a snapshot of all attributes held by this element.
45
45
* Designated mainly for debugging.
46
46
*/
47
- val allAttributes : Map <IrAttribute <* , * >, Any >
47
+ val attributes : Map <IrAttribute <* , * >, Any >
48
48
get() {
49
- val attributeMap = attributeMap
49
+ val attributes = _attributes
50
50
? : return emptyMap()
51
- return buildMap(attributeMap .size / 2 ) {
52
- for (i in attributeMap .indices step 2 ) {
53
- val key = attributeMap [i] as IrAttribute <* , * >?
51
+ return buildMap(attributes .size / 2 ) {
52
+ for (i in attributes .indices step 2 ) {
53
+ val key = attributes [i] as IrAttribute <* , * >?
54
54
? : break
55
- val value = attributeMap [i + 1 ]!!
55
+ val value = attributes [i + 1 ]!!
56
56
put(key, value)
57
57
}
58
58
}
@@ -64,28 +64,28 @@ abstract class IrElementBase : IrElement {
64
64
return null
65
65
} else {
66
66
@Suppress(" UNCHECKED_CAST" )
67
- return attributeMap !! [foundIndex + 1 ] as T
67
+ return _attributes !! [foundIndex + 1 ] as T
68
68
}
69
69
}
70
70
71
71
internal fun <T : Any > setAttributeInternal (key : IrAttribute <* , T >, value : T ? ): T ? {
72
72
val foundIndex = findAttributeIndex(key)
73
73
val previousValue: T ? = if (foundIndex >= 0 ) {
74
74
@Suppress(" UNCHECKED_CAST" )
75
- attributeMap !! [foundIndex + 1 ] as T
75
+ _attributes !! [foundIndex + 1 ] as T
76
76
} else null
77
77
78
78
putAttribute(foundIndex, key, value)
79
79
return previousValue
80
80
}
81
81
82
82
private fun findAttributeIndex (key : IrAttribute <* , * >): Int {
83
- val attributeMap = attributeMap
83
+ val attributes = _attributes
84
84
? : return - 1
85
85
86
86
var i = 0
87
- while (i < attributeMap .size) {
88
- val foundKey = attributeMap [i]
87
+ while (i < attributes .size) {
88
+ val foundKey = attributes [i]
89
89
? : break
90
90
if (foundKey == = key) {
91
91
return i
@@ -98,21 +98,21 @@ abstract class IrElementBase : IrElement {
98
98
99
99
private fun <T : Any > initializeAttributes (firstKey : IrAttribute <* , T >, firstValue : T ) {
100
100
val initialSlots = 1
101
- val attributeMap = arrayOfNulls<Any ?>(initialSlots * 2 )
102
- attributeMap [0 ] = firstKey
103
- attributeMap [1 ] = firstValue
104
- this .attributeMap = attributeMap
101
+ val attributes = arrayOfNulls<Any ?>(initialSlots * 2 )
102
+ attributes [0 ] = firstKey
103
+ attributes [1 ] = firstValue
104
+ this ._attributes = attributes
105
105
}
106
106
107
107
private fun <T : Any > putAttribute (existingIndex : Int , key : IrAttribute <* , T >, value : T ? ) {
108
108
if (existingIndex >= 0 ) {
109
109
if (value == null ) {
110
110
removeAttributeAt(existingIndex)
111
111
} else {
112
- attributeMap !! [existingIndex + 1 ] = value
112
+ _attributes !! [existingIndex + 1 ] = value
113
113
}
114
114
} else if (value != null ) {
115
- if (attributeMap == null ) {
115
+ if (_attributes == null ) {
116
116
initializeAttributes(key, value)
117
117
} else {
118
118
val newEntryIndex = existingIndex.inv ()
@@ -122,33 +122,33 @@ abstract class IrElementBase : IrElement {
122
122
}
123
123
124
124
private fun <T : Any > addAttributeAt (index : Int , key : IrAttribute <* , T >, value : T ) {
125
- var attributeMap = attributeMap !!
126
- if (attributeMap .size <= index) {
125
+ var attributes = _attributes !!
126
+ if (attributes .size <= index) {
127
127
val newSlots = 2
128
- attributeMap = attributeMap .copyOf(attributeMap .size + newSlots * 2 )
129
- this .attributeMap = attributeMap
128
+ attributes = attributes .copyOf(attributes .size + newSlots * 2 )
129
+ this ._attributes = attributes
130
130
}
131
131
132
- attributeMap [index] = key
133
- attributeMap [index + 1 ] = value
132
+ attributes [index] = key
133
+ attributes [index + 1 ] = value
134
134
}
135
135
136
136
private fun removeAttributeAt (keyIndex : Int ) {
137
137
// It is expected that during the compilation process, attributes are mostly appended
138
138
// and rarely removed, hence no need to shrink the array.
139
139
140
- val attributeMap = attributeMap !!
140
+ val attributes = _attributes !!
141
141
142
- var lastKeyIndex = attributeMap .size - 2
143
- while (lastKeyIndex > keyIndex && attributeMap [lastKeyIndex] == null ) {
142
+ var lastKeyIndex = attributes .size - 2
143
+ while (lastKeyIndex > keyIndex && attributes [lastKeyIndex] == null ) {
144
144
lastKeyIndex - = 2
145
145
}
146
146
147
147
if (lastKeyIndex > keyIndex) {
148
- attributeMap [keyIndex] = attributeMap [lastKeyIndex]
149
- attributeMap [keyIndex + 1 ] = attributeMap [lastKeyIndex + 1 ]
148
+ attributes [keyIndex] = attributes [lastKeyIndex]
149
+ attributes [keyIndex + 1 ] = attributes [lastKeyIndex + 1 ]
150
150
}
151
- attributeMap [lastKeyIndex] = null
152
- attributeMap [lastKeyIndex + 1 ] = null
151
+ attributes [lastKeyIndex] = null
152
+ attributes [lastKeyIndex + 1 ] = null
153
153
}
154
154
}
0 commit comments