Skip to content

Commit

Permalink
kt-fast-collections: fix array init performance bug
Browse files Browse the repository at this point in the history
  • Loading branch information
multun committed Mar 6, 2024
1 parent b1f8892 commit 1f27b88
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,16 @@ private fun CollectionItemType.generateArray(context: GeneratorContext, currentF
import ${type.qualifiedName}
// regular lambda types are compiled to a generic Function<In, Out> type, which boxes
// its arguments and return value. It's a significant performance bug.
fun interface ${simpleName}ArrayInitializer${paramsDecl} {
fun call(idx: Int): $type
}
@JvmInline
value class Mutable${simpleName}Array${paramsDecl}(private val data: $bufferType) {
public constructor(size: Int, init: (Int) -> $type) : this($bufferType(size) { i -> ${storageType.toPrimitive("init(i)")} })
public constructor(size: Int, init: ${simpleName}ArrayInitializer${paramsUse})
: this($bufferType(size) { i -> ${storageType.toPrimitive("init.call(i)")} })
val size get() = data.size
Expand Down

0 comments on commit 1f27b88

Please sign in to comment.