[K/N] Fix performance build

This commit is contained in:
Alexander Shabalin
2023-07-03 11:46:31 +02:00
committed by Space Team
parent 4081115774
commit e1b168d77c
4 changed files with 6 additions and 0 deletions
@@ -127,7 +127,9 @@ operator fun Float32Buffer.set(index: Int, value: Float): Unit = mbuffer.setFloa
fun MemBufferAlloc(size: Int): MemBuffer = MemBuffer(ByteArray(size)) fun MemBufferAlloc(size: Int): MemBuffer = MemBuffer(ByteArray(size))
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
fun MemBuffer.getFloat(index: Int): Float = data.getFloatAt(index) fun MemBuffer.getFloat(index: Int): Float = data.getFloatAt(index)
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
fun MemBuffer.setFloat(index: Int, value: Float): Unit = data.setFloatAt(index, value) fun MemBuffer.setFloat(index: Int, value: Float): Unit = data.setFloatAt(index, value)
fun MemBuffer.asFloat32Buffer(): Float32Buffer = this.sliceFloat32Buffer() fun MemBuffer.asFloat32Buffer(): Float32Buffer = this.sliceFloat32Buffer()
@@ -25,6 +25,7 @@ class Generation(private val width: Int, private val height: Int) {
} }
} }
} }
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
assert(neighborhood.size == 8) assert(neighborhood.size == 8)
val aliveNeighbours = neighborhood val aliveNeighbours = neighborhood
.map { wrapOverEdge(it) } .map { wrapOverEdge(it) }
@@ -22,11 +22,13 @@ private class Data(var x: Int = Random.nextInt(1000) + 1)
private class ReferenceWrapper private constructor( private class ReferenceWrapper private constructor(
data: Data data: Data
) { ) {
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
private val weak = WeakReference(data) private val weak = WeakReference(data)
private val strong = StableRef.create(data) private val strong = StableRef.create(data)
val value: Int val value: Int
get() { get() {
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
val ref: Data? = weak.value val ref: Data? = weak.value
if (ref == null) { if (ref == null) {
return 0 return 0
@@ -31,6 +31,7 @@ actual fun writeToFile(fileName: String, text: String) {
} }
// Wrapper for assert funtion in stdlib // Wrapper for assert funtion in stdlib
@OptIn(kotlin.experimental.ExperimentalNativeApi::class)
actual fun assert(value: Boolean) { actual fun assert(value: Boolean) {
kotlin.assert(value) kotlin.assert(value)
} }