Use Array constructor with size to create Array of nulls
Change the constructor visibility from public to private as it should be.
This commit is contained in:
committed by
Space Team
parent
a6520a294b
commit
77491ded1b
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_217
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_295
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_579
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_579
|
||||||
|
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 49_207
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 48_188
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_605
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_605
|
||||||
|
|
||||||
fun box(): String {
|
fun box(): String {
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 15_582
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 13_660
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_134
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 6_134
|
||||||
|
|
||||||
// FILE: test.kt
|
// FILE: test.kt
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// TARGET_BACKEND: WASM
|
// TARGET_BACKEND: WASM
|
||||||
|
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 14_259
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: wasm 12_337
|
||||||
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451
|
// WASM_DCE_EXPECTED_OUTPUT_SIZE: mjs 5_451
|
||||||
|
|
||||||
fun box() = "OK"
|
fun box() = "OK"
|
||||||
@@ -14,7 +14,7 @@ import kotlin.wasm.internal.*
|
|||||||
* See [Kotlin language documentation](https://kotlinlang.org/docs/reference/basic-types.html#arrays)
|
* See [Kotlin language documentation](https://kotlinlang.org/docs/reference/basic-types.html#arrays)
|
||||||
* for more information on arrays.
|
* for more information on arrays.
|
||||||
*/
|
*/
|
||||||
public class Array<T> constructor(size: Int) {
|
public class Array<T> @PublishedApi internal constructor(size: Int) {
|
||||||
internal val storage: WasmAnyArray = WasmAnyArray(size)
|
internal val storage: WasmAnyArray = WasmAnyArray(size)
|
||||||
|
|
||||||
@Suppress("TYPE_PARAMETER_AS_REIFIED", "UNUSED_PARAMETER", "CAST_NEVER_SUCCEEDS")
|
@Suppress("TYPE_PARAMETER_AS_REIFIED", "UNUSED_PARAMETER", "CAST_NEVER_SUCCEEDS")
|
||||||
@@ -28,6 +28,7 @@ public class Array<T> constructor(size: Int) {
|
|||||||
* The function [init] is called for each array element sequentially starting from the first one.
|
* The function [init] is called for each array element sequentially starting from the first one.
|
||||||
* It should return the value for an array element given its index.
|
* It should return the value for an array element given its index.
|
||||||
*/
|
*/
|
||||||
|
// TODO: it have to be inline
|
||||||
@Suppress("TYPE_PARAMETER_AS_REIFIED")
|
@Suppress("TYPE_PARAMETER_AS_REIFIED")
|
||||||
public constructor(size: Int, init: (Int) -> T) : this(size) {
|
public constructor(size: Int, init: (Int) -> T) : this(size) {
|
||||||
storage.fill(size, init)
|
storage.fill(size, init)
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public operator fun String?.plus(other: Any?): String = (this ?: "null") + other
|
|||||||
*/
|
*/
|
||||||
// TODO: Should T be reified?
|
// TODO: Should T be reified?
|
||||||
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
@Suppress("REIFIED_TYPE_PARAMETER_NO_INLINE")
|
||||||
public fun <@PureReifiable reified T> arrayOfNulls(size: Int): Array<T?> = Array(size) { null }
|
public fun <@PureReifiable reified T> arrayOfNulls(size: Int): Array<T?> = Array(size)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array containing the specified elements.
|
* Returns an array containing the specified elements.
|
||||||
|
|||||||
@@ -119,4 +119,4 @@ internal fun stringGetPoolSize(): Int =
|
|||||||
// This initializer is a special case in FieldInitializersLowering
|
// This initializer is a special case in FieldInitializersLowering
|
||||||
@Suppress("DEPRECATION")
|
@Suppress("DEPRECATION")
|
||||||
@EagerInitialization
|
@EagerInitialization
|
||||||
internal val stringPool: Array<String?> = arrayOfNulls(stringGetPoolSize())
|
internal val stringPool: Array<String?> = Array(stringGetPoolSize())
|
||||||
Reference in New Issue
Block a user