From 51f2ec68fb2938bf562a1727459f49022d33c8a8 Mon Sep 17 00:00:00 2001 From: Iaroslav Postovalov Date: Tue, 5 Jan 2021 22:55:27 +0700 Subject: [PATCH] Delete wrap function --- .../kotlin/space/kscience/kmath/memory/Memory.kt | 6 ------ .../space/kscience/kmath/memory/DataViewMemory.kt | 10 ---------- .../space/kscience/kmath/memory/ByteBufferMemory.kt | 7 ------- .../kotlin/space/kscience/kmath/memory/NativeMemory.kt | 6 ------ 4 files changed, 29 deletions(-) diff --git a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt index c784575a1..a80e9e1e8 100644 --- a/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt +++ b/kmath-memory/src/commonMain/kotlin/space/kscience/kmath/memory/Memory.kt @@ -157,9 +157,3 @@ public inline fun Memory.write(block: MemoryWriter.() -> Unit) { * Allocates the most effective platform-specific memory. */ public expect fun Memory.Companion.allocate(length: Int): Memory - -/** - * Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied - * and could be mutated independently from the resulting [Memory]. - */ -public expect fun Memory.Companion.wrap(array: ByteArray): Memory diff --git a/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt b/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt index 8ac97b759..043494525 100644 --- a/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt +++ b/kmath-memory/src/jsMain/kotlin/space/kscience/kmath/memory/DataViewMemory.kt @@ -7,7 +7,6 @@ package space.kscience.kmath.memory import org.khronos.webgl.ArrayBuffer import org.khronos.webgl.DataView -import org.khronos.webgl.Int8Array private class DataViewMemory(val view: DataView) : Memory { override val size: Int get() = view.byteLength @@ -91,12 +90,3 @@ public actual fun Memory.Companion.allocate(length: Int): Memory { val buffer = ArrayBuffer(length) return DataViewMemory(DataView(buffer, 0, length)) } - -/** - * Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied - * and could be mutated independently from the resulting [Memory]. - */ -public actual fun Memory.Companion.wrap(array: ByteArray): Memory { - val int8Array = array.unsafeCast() - return DataViewMemory(DataView(int8Array.buffer, int8Array.byteOffset, int8Array.length)) -} diff --git a/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt b/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt index 41a426ea8..b67e83e04 100644 --- a/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt +++ b/kmath-memory/src/jvmMain/kotlin/space/kscience/kmath/memory/ByteBufferMemory.kt @@ -102,13 +102,6 @@ internal class ByteBufferMemory( public actual fun Memory.Companion.allocate(length: Int): Memory = ByteBufferMemory(checkNotNull(ByteBuffer.allocate(length).order(ByteOrder.LITTLE_ENDIAN))) -/** - * Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied - * and could be mutated independently from the resulting [Memory]. - */ -public actual fun Memory.Companion.wrap(array: ByteArray): Memory = - ByteBufferMemory(checkNotNull(ByteBuffer.wrap(array))) - /** * Wraps this [ByteBuffer] to [Memory] object. * diff --git a/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt b/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt index 952ce5896..08b882b9e 100644 --- a/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt +++ b/kmath-memory/src/nativeMain/kotlin/space/kscience/kmath/memory/NativeMemory.kt @@ -83,12 +83,6 @@ internal class NativeMemory( override fun writer(): MemoryWriter = writer } -/** - * Wraps a [Memory] around existing [ByteArray]. This operation is unsafe since the array is not copied - * and could be mutated independently from the resulting [Memory]. - */ -public actual fun Memory.Companion.wrap(array: ByteArray): Memory = NativeMemory(array) - /** * Allocates the most effective platform-specific memory. */