Skip to content

Commit 021bb9d

Browse files
committed
Rename ObjectWrapper to ObjectRef
1 parent c3b3886 commit 021bb9d

File tree

3 files changed

+16
-16
lines changed

3 files changed

+16
-16
lines changed

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/PersistentVector.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
9999
return insertIntoTail(root, index - rootSize, element)
100100
}
101101

102-
val elementCarry = ObjectWrapper(null)
102+
val elementCarry = ObjectRef(null)
103103
val newRoot = insertIntoRoot(root, rootShift, index, element, elementCarry)
104104
return insertIntoTail(newRoot, 0, elementCarry.value)
105105
}
@@ -126,7 +126,7 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
126126
*
127127
* @return new root trie
128128
*/
129-
private fun insertIntoRoot(root: Array<Any?>, shift: Int, index: Int, element: Any?, elementCarry: ObjectWrapper): Array<Any?> {
129+
private fun insertIntoRoot(root: Array<Any?>, shift: Int, index: Int, element: Any?, elementCarry: ObjectRef): Array<Any?> {
130130
val bufferIndex = indexSegment(index, shift)
131131

132132
if (shift == 0) {
@@ -159,7 +159,7 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
159159
if (index >= rootSize) {
160160
return removeFromTailAt(root, rootSize, rootShift, index - rootSize)
161161
}
162-
val newRoot = removeFromRootAt(root, rootShift, index, ObjectWrapper(tail[0]))
162+
val newRoot = removeFromRootAt(root, rootShift, index, ObjectRef(tail[0]))
163163
return removeFromTailAt(newRoot, rootSize, rootShift, 0)
164164
}
165165

@@ -191,7 +191,7 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
191191
if (shift == 0) {
192192
return SmallPersistentVector(root)
193193
}
194-
val tailCarry = ObjectWrapper(null)
194+
val tailCarry = ObjectRef(null)
195195
val newRoot = pullLastBuffer(root, shift, rootSize - 1, tailCarry)!!
196196
@Suppress("UNCHECKED_CAST")
197197
val newTail = tailCarry.value as Array<Any?>
@@ -211,7 +211,7 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
211211
*
212212
* [tailCarry] on output contains the extracted leaf buffer.
213213
*/
214-
private fun pullLastBuffer(root: Array<Any?>, shift: Int, index: Int, tailCarry: ObjectWrapper): Array<Any?>? {
214+
private fun pullLastBuffer(root: Array<Any?>, shift: Int, index: Int, tailCarry: ObjectRef): Array<Any?>? {
215215
val bufferIndex = indexSegment(index, shift)
216216

217217
val newBufferAtIndex = if (shift == LOG_MAX_BUFFER_SIZE) {
@@ -239,14 +239,14 @@ internal class PersistentVector<E>(private val root: Array<Any?>,
239239
*
240240
* @return the new root of the trie.
241241
*/
242-
private fun removeFromRootAt(root: Array<Any?>, shift: Int, index: Int, tailCarry: ObjectWrapper): Array<Any?> {
242+
private fun removeFromRootAt(root: Array<Any?>, shift: Int, index: Int, tailCarry: ObjectRef): Array<Any?> {
243243
val bufferIndex = indexSegment(index, shift)
244244

245245
if (shift == 0) {
246246
val newRoot = if (bufferIndex == 0) arrayOfNulls<Any?>(MAX_BUFFER_SIZE) else root.copyOf(MAX_BUFFER_SIZE)
247247
root.copyInto(newRoot, bufferIndex, bufferIndex + 1, MAX_BUFFER_SIZE)
248248
newRoot[MAX_BUFFER_SIZE - 1] = tailCarry.value
249-
tailCarry.value = root[0]
249+
tailCarry.value = root[bufferIndex]
250250
return newRoot
251251
}
252252

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/PersistentVectorBuilder.kt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
156156
return
157157
}
158158

159-
val elementCarry = ObjectWrapper(null)
159+
val elementCarry = ObjectRef(null)
160160
val newRest = insertIntoRoot(root!!, rootShift, index, element, elementCarry)
161161
insertIntoTail(newRest, 0, elementCarry.value as E)
162162
}
@@ -186,7 +186,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
186186
*
187187
* @return new root trie or this modified trie, if it's already mutable
188188
*/
189-
private fun insertIntoRoot(root: Array<Any?>, shift: Int, index: Int, element: Any?, elementCarry: ObjectWrapper): Array<Any?> {
189+
private fun insertIntoRoot(root: Array<Any?>, shift: Int, index: Int, element: Any?, elementCarry: ObjectRef): Array<Any?> {
190190
val bufferIndex = indexSegment(index, shift)
191191

192192
if (shift == 0) {
@@ -246,7 +246,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
246246
@Suppress("UNCHECKED_CAST")
247247
return removeFromTailAt(root, rootSize, rootShift, index - rootSize) as E
248248
}
249-
val elementCarry = ObjectWrapper(tail[0])
249+
val elementCarry = ObjectRef(tail[0])
250250
val newRoot = removeFromRootAt(root!!, rootShift, index, elementCarry)
251251
removeFromTailAt(newRoot, rootSize, rootShift, 0)
252252
@Suppress("UNCHECKED_CAST")
@@ -282,7 +282,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
282282
*
283283
* @return the new root of the trie.
284284
*/
285-
private fun removeFromRootAt(root: Array<Any?>, shift: Int, index: Int, tailCarry: ObjectWrapper): Array<Any?> {
285+
private fun removeFromRootAt(root: Array<Any?>, shift: Int, index: Int, tailCarry: ObjectRef): Array<Any?> {
286286
val bufferIndex = indexSegment(index, shift)
287287

288288
if (shift == 0) {
@@ -329,7 +329,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
329329
return
330330
}
331331

332-
val tailCarry = ObjectWrapper(null)
332+
val tailCarry = ObjectRef(null)
333333
val newRoot = pullLastBuffer(root!!, shift, rootSize, tailCarry)!!
334334
@Suppress("UNCHECKED_CAST")
335335
this.tail = tailCarry.value as Array<Any?>
@@ -352,7 +352,7 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
352352
*
353353
* [tailCarry] on output contains the extracted leaf buffer.
354354
*/
355-
private fun pullLastBuffer(root: Array<Any?>, shift: Int, rootSize: Int, tailCarry: ObjectWrapper): Array<Any?>? {
355+
private fun pullLastBuffer(root: Array<Any?>, shift: Int, rootSize: Int, tailCarry: ObjectRef): Array<Any?>? {
356356
val bufferIndex = indexSegment(rootSize - 1, shift)
357357

358358
val newBufferAtIndex = if (shift == LOG_MAX_BUFFER_SIZE) {
@@ -384,13 +384,13 @@ class PersistentVectorBuilder<E>(private var vector: PersistentList<E>,
384384
return oldElement as E
385385
}
386386

387-
val oldElementCarry = ObjectWrapper(null)
387+
val oldElementCarry = ObjectRef(null)
388388
this.root = setInRoot(root!!, rootShift, index, element, oldElementCarry)
389389
@Suppress("UNCHECKED_CAST")
390390
return oldElementCarry.value as E
391391
}
392392

393-
private fun setInRoot(root: Array<Any?>, shift: Int, index: Int, e: E, oldElementCarry: ObjectWrapper): Array<Any?> {
393+
private fun setInRoot(root: Array<Any?>, shift: Int, index: Int, e: E, oldElementCarry: ObjectRef): Array<Any?> {
394394
val bufferIndex = indexSegment(index, shift)
395395
val mutableRoot = makeMutable(root)
396396

kotlinx-collections-immutable/src/main/kotlin/kotlinx/collections/immutable/implementations/immutableList/Utils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ internal const val LOG_MAX_BUFFER_SIZE = 5
2323
internal const val MAX_BUFFER_SIZE_MINUS_ONE = MAX_BUFFER_SIZE - 1
2424
internal const val MUTABLE_BUFFER_SIZE = MAX_BUFFER_SIZE + 1
2525

26-
internal class ObjectWrapper(var value: Any?) // TODO: name: ElementReference, ElementRef, ObjectCarry, CarryRef
26+
internal class ObjectRef(var value: Any?)
2727

2828
internal fun <E> persistentVectorOf(): PersistentList<E> {
2929
return SmallPersistentVector.EMPTY

0 commit comments

Comments
 (0)