Skip to content

Commit f5ba526

Browse files
authored
Remove unnecessary Int8Array type definition (#54)
1 parent f511169 commit f5ba526

6 files changed

Lines changed: 4 additions & 105 deletions

File tree

library/crypto-rand/src/jsMain/kotlin/org/kotlincrypto/random/internal/js/_JsCrypto.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
**/
1616
package org.kotlincrypto.random.internal.js
1717

18-
import kotlin.math.min
18+
import kotlin.js.unsafeCast
1919

2020
internal actual val IS_NODE_JS: Boolean by lazy { isNodeJs() }
2121

@@ -25,13 +25,13 @@ internal actual fun jsCryptoNode(): JsCrypto = js(CODE_JS_CRYPTO_NODE)
2525
private fun isNodeJs(): Boolean = js(CODE_IS_NODE_JS)
2626

2727
internal actual fun ByteArray.cryptoRandFill(procure: (JsUint8Array) -> Unit) {
28-
val a = asJsInt8Array().asJsUint8Array()
28+
val a = JsUint8Array.new(unsafeCast<JsTypedArrayLike>().buffer)
2929
if (a.length < JS_CRYPTO_MAX_FILL) return procure(a)
3030

3131
var remainder = size
3232
var offset = 0
3333
while (remainder > 0) {
34-
val len = min(JS_CRYPTO_MAX_FILL, remainder)
34+
val len = minOf(JS_CRYPTO_MAX_FILL, remainder)
3535
val s = a.subarray(start = offset, end = offset + len)
3636
procure(s)
3737
offset += len

library/crypto-rand/src/jsMain/kotlin/org/kotlincrypto/random/internal/js/_JsInt8Array.kt

Lines changed: 0 additions & 28 deletions
This file was deleted.

library/crypto-rand/src/jsWasmJsMain/kotlin/org/kotlincrypto/random/internal/js/JsInt8Array.kt

Lines changed: 0 additions & 45 deletions
This file was deleted.

library/crypto-rand/src/jsWasmJsMain/kotlin/org/kotlincrypto/random/internal/js/JsUint8Array.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ internal inline fun JsUint8Array.Companion.new(buffer: JsArrayBufferLike): JsUin
3333
internal inline operator fun JsUint8Array.get(index: Int): Byte = jsUint8ArrayGet(this, index).toByte()
3434
internal inline operator fun JsUint8Array.set(index: Int, value: UByte) { jsUint8ArraySet(this, index, value.toByte()) }
3535

36-
internal inline fun JsUint8Array.asJsInt8Array(): JsInt8Array = JsInt8Array.new(buffer)
37-
3836
internal const val CODE_JS_NEW_UINT8_LENGTH = "new Uint8Array(length)"
3937
internal const val CODE_JS_NEW_UINT8_BUFFER = "new Uint8Array(buffer)"
4038

library/crypto-rand/src/wasmJsMain/kotlin/org/kotlincrypto/random/internal/js/_JsCrypto.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.kotlincrypto.random.internal.js
1919

20-
import kotlin.math.min
21-
2220
internal actual val IS_NODE_JS: Boolean by lazy { isNodeJs() }
2321

2422
internal actual fun jsCryptoBrowser(): JsCrypto = js(CODE_JS_CRYPTO_BROWSER)
@@ -32,7 +30,7 @@ internal actual fun ByteArray.cryptoRandFill(procure: (JsUint8Array) -> Unit) {
3230
// Kotlin/WasmJs does not provide access to ByteArray.storage
3331
// (i.e. the WasmByteArray), so we must always use a buffer and
3432
// copy back and forth.
35-
val buf = JsUint8Array.new(length = min(size, BUFFER_SIZE))
33+
val buf = JsUint8Array.new(length = minOf(size, BUFFER_SIZE))
3634

3735
try {
3836
var remainder = size

library/crypto-rand/src/wasmJsMain/kotlin/org/kotlincrypto/random/internal/js/_JsInt8Array.kt

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)