@@ -270,7 +270,7 @@ internal class TrieNode<K, V>(
270
270
private fun mutableRemoveEntryAtIndex (keyIndex : Int , positionMask : Int , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V >? {
271
271
// assert(hasEntryAt(positionMask))
272
272
mutator.size--
273
- mutator.operationResult = buffer[ keyIndex + 1 ] as V
273
+ mutator.operationResult = valueAtKeyIndex( keyIndex)
274
274
if (buffer.size == ENTRY_SIZE ) return null
275
275
276
276
if (marker == = mutator.marker) {
@@ -291,8 +291,7 @@ internal class TrieNode<K, V>(
291
291
292
292
private fun mutableCollisionRemoveEntryAtIndex (i : Int , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V >? {
293
293
mutator.size--
294
- @Suppress(" UNCHECKED_CAST" )
295
- mutator.operationResult = buffer[i + 1 ] as V
294
+ mutator.operationResult = valueAtKeyIndex(i)
296
295
if (buffer.size == ENTRY_SIZE ) return null
297
296
298
297
if (marker == = mutator.marker) {
@@ -333,18 +332,17 @@ internal class TrieNode<K, V>(
333
332
334
333
private fun collisionGet (key : K ): V ? {
335
334
for (i in 0 until buffer.size step ENTRY_SIZE ) {
336
- if (key == buffer[i]) {
337
- @Suppress(" UNCHECKED_CAST" )
338
- return buffer[i + 1 ] as V
335
+ if (key == keyAtIndex(i)) {
336
+ return valueAtKeyIndex(i)
339
337
}
340
338
}
341
339
return null
342
340
}
343
341
344
342
private fun collisionPut (key : K , value : V ): ModificationResult <K , V >? {
345
343
for (i in 0 until buffer.size step ENTRY_SIZE ) {
346
- if (key == buffer[i] ) {
347
- if (value == = buffer[i + 1 ] ) {
344
+ if (key == keyAtIndex(i) ) {
345
+ if (value == = valueAtKeyIndex(i) ) {
348
346
return null
349
347
}
350
348
val newBuffer = buffer.copyOf()
@@ -359,9 +357,8 @@ internal class TrieNode<K, V>(
359
357
private fun mutableCollisionPut (key : K , value : V , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V > {
360
358
// Check if there is an entry with the specified key.
361
359
for (i in 0 until buffer.size step ENTRY_SIZE ) {
362
- if (key == buffer[i]) { // found entry with the specified key
363
- @Suppress(" UNCHECKED_CAST" )
364
- mutator.operationResult = buffer[i + 1 ] as V
360
+ if (key == keyAtIndex(i)) { // found entry with the specified key
361
+ mutator.operationResult = valueAtKeyIndex(i)
365
362
366
363
// If the [mutator] is exclusive owner of this node, update value of the entry in-place.
367
364
if (marker == = mutator.marker) {
@@ -385,7 +382,7 @@ internal class TrieNode<K, V>(
385
382
386
383
private fun collisionRemove (key : K ): TrieNode <K , V >? {
387
384
for (i in 0 until buffer.size step ENTRY_SIZE ) {
388
- if (key == buffer[i] ) {
385
+ if (key == keyAtIndex(i) ) {
389
386
return collisionRemoveEntryAtIndex(i)
390
387
}
391
388
}
@@ -394,7 +391,7 @@ internal class TrieNode<K, V>(
394
391
395
392
private fun mutableCollisionRemove (key : K , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V >? {
396
393
for (i in 0 until buffer.size step ENTRY_SIZE ) {
397
- if (key == buffer[i] ) {
394
+ if (key == keyAtIndex(i) ) {
398
395
return mutableCollisionRemoveEntryAtIndex(i, mutator)
399
396
}
400
397
}
@@ -403,7 +400,7 @@ internal class TrieNode<K, V>(
403
400
404
401
private fun collisionRemove (key : K , value : V ): TrieNode <K , V >? {
405
402
for (i in 0 until buffer.size step ENTRY_SIZE ) {
406
- if (key == buffer[i] && value == buffer[i + 1 ] ) {
403
+ if (key == keyAtIndex(i) && value == valueAtKeyIndex(i) ) {
407
404
return collisionRemoveEntryAtIndex(i)
408
405
}
409
406
}
@@ -412,7 +409,7 @@ internal class TrieNode<K, V>(
412
409
413
410
private fun mutableCollisionRemove (key : K , value : V , mutator : PersistentHashMapBuilder <K , V >): TrieNode <K , V >? {
414
411
for (i in 0 until buffer.size step ENTRY_SIZE ) {
415
- if (key == buffer[i] && value == buffer[i + 1 ] ) {
412
+ if (key == keyAtIndex(i) && value == valueAtKeyIndex(i) ) {
416
413
return mutableCollisionRemoveEntryAtIndex(i, mutator)
417
414
}
418
415
}
0 commit comments