Skip to content

Commit 617eb5f

Browse files
authored
Use fastArrayBufferToByteArray in TestWasmResourceReader too (#5551)
I missed this when doing #5550 ## Testing N/A ## Release Notes N/A
1 parent f64b59e commit 617eb5f

1 file changed

Lines changed: 1 addition & 17 deletions

File tree

components/resources/library/src/wasmJsMain/kotlin/org/jetbrains/compose/resources/ResourceReader.wasmJs.kt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@ import kotlinx.browser.window
44
import kotlinx.coroutines.await
55
import org.khronos.webgl.ArrayBuffer
66
import org.khronos.webgl.Int8Array
7-
import org.w3c.fetch.Response
87
import org.w3c.files.Blob
98
import org.w3c.xhr.XMLHttpRequest
109
import kotlin.js.Promise
11-
import kotlin.wasm.unsafe.UnsafeWasmMemoryApi
12-
import kotlin.wasm.unsafe.withScopedMemoryAllocator
1310

1411
@JsFun(
1512
""" (src, size, dstAddr) => {
@@ -85,24 +82,11 @@ private object TestWasmResourceReader : ResourceReader {
8582
request.overrideMimeType("text/plain; charset=x-user-defined")
8683
request.send()
8784
if (request.status == 200.toShort()) {
88-
return requestResponseAsByteArray(request).asByteArray()
85+
return fastArrayBufferToByteArray(requestResponseAsByteArray(request).buffer)
8986
}
9087
println("Request status is not 200 - $resPath, status: ${request.status}")
9188
throw MissingResourceException(resPath)
9289
}
93-
94-
private fun Int8Array.asByteArray(): ByteArray {
95-
val array = this
96-
val size = array.length
97-
98-
@OptIn(UnsafeWasmMemoryApi::class)
99-
return withScopedMemoryAllocator { allocator ->
100-
val memBuffer = allocator.allocate(size)
101-
val dstAddress = memBuffer.address.toInt()
102-
jsExportInt8ArrayToWasm(array, size, dstAddress)
103-
ByteArray(size) { i -> (memBuffer + i).loadByte() }
104-
}
105-
}
10690
}
10791

10892
// For blocking XmlHttpRequest the response can be only in text form, so we convert it to bytes manually

0 commit comments

Comments
 (0)