Skip to content

Commit 1f27b88

Browse files
committed
kt-fast-collections: fix array init performance bug
1 parent b1f8892 commit 1f27b88

File tree

1 file changed

+8
-1
lines changed
  • core/kt-fast-collections-generator/src/main/kotlin/collections

1 file changed

+8
-1
lines changed

core/kt-fast-collections-generator/src/main/kotlin/collections/Array.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,16 @@ private fun CollectionItemType.generateArray(context: GeneratorContext, currentF
2929
3030
import ${type.qualifiedName}
3131
32+
// regular lambda types are compiled to a generic Function<In, Out> type, which boxes
33+
// its arguments and return value. It's a significant performance bug.
34+
fun interface ${simpleName}ArrayInitializer${paramsDecl} {
35+
fun call(idx: Int): $type
36+
}
37+
3238
@JvmInline
3339
value class Mutable${simpleName}Array${paramsDecl}(private val data: $bufferType) {
34-
public constructor(size: Int, init: (Int) -> $type) : this($bufferType(size) { i -> ${storageType.toPrimitive("init(i)")} })
40+
public constructor(size: Int, init: ${simpleName}ArrayInitializer${paramsUse})
41+
: this($bufferType(size) { i -> ${storageType.toPrimitive("init.call(i)")} })
3542
3643
val size get() = data.size
3744

0 commit comments

Comments
 (0)