diff --git a/js/js.libraries/src/core/generated/_ArraysJs.kt b/js/js.libraries/src/core/generated/_ArraysJs.kt index 59b476578ff..4b422050ddc 100644 --- a/js/js.libraries/src/core/generated/_ArraysJs.kt +++ b/js/js.libraries/src/core/generated/_ArraysJs.kt @@ -13057,134 +13057,6 @@ public inline fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray return this.asDynamic().slice(fromIndex, toIndex) } -/** - * Sorts the array in-place. - */ -@library("primitiveArraySort") -public fun IntArray.sort(): Unit { - noImpl -} - -/** - * Sorts the array in-place. - */ -public fun LongArray.sort(): Unit { - if (size > 1) - sort { a: Long, b: Long -> a.compareTo(b) } -} - -/** - * Sorts the array in-place. - */ -@library("primitiveArraySort") -public fun ByteArray.sort(): Unit { - noImpl -} - -/** - * Sorts the array in-place. - */ -@library("primitiveArraySort") -public fun ShortArray.sort(): Unit { - noImpl -} - -/** - * Sorts the array in-place. - */ -@library("primitiveArraySort") -public fun DoubleArray.sort(): Unit { - noImpl -} - -/** - * Sorts the array in-place. - */ -@library("primitiveArraySort") -public fun FloatArray.sort(): Unit { - noImpl -} - -/** - * Sorts the array in-place. - */ -@library("primitiveArraySort") -public fun CharArray.sort(): Unit { - noImpl -} - -/** - * Sorts the array in-place according to the natural order of its elements. - */ -public fun > Array.sort(): Unit { - if (size > 1) - sort { a: T, b: T -> a.compareTo(b) } -} - -/** - * Sorts the array in-place according to the order specified by the given [comparator]. - */ -public fun Array.sortWith(comparator: Comparator): Unit { - if (size > 1) - sort { a, b -> comparator.compare(a, b) } -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun ByteArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun ShortArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun IntArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun LongArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun FloatArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun DoubleArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun BooleanArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public fun CharArray.toTypedArray(): Array { - return copyOf().unsafeCast>() -} - /** * Returns an array containing all elements of the original array and then the given [element]. */ @@ -13400,6 +13272,134 @@ public inline fun Array.plusElement(element: T): Array { return this.asDynamic().concat(arrayOf(element)) } +/** + * Sorts the array in-place. + */ +@library("primitiveArraySort") +public fun IntArray.sort(): Unit { + noImpl +} + +/** + * Sorts the array in-place. + */ +public fun LongArray.sort(): Unit { + if (size > 1) + sort { a: Long, b: Long -> a.compareTo(b) } +} + +/** + * Sorts the array in-place. + */ +@library("primitiveArraySort") +public fun ByteArray.sort(): Unit { + noImpl +} + +/** + * Sorts the array in-place. + */ +@library("primitiveArraySort") +public fun ShortArray.sort(): Unit { + noImpl +} + +/** + * Sorts the array in-place. + */ +@library("primitiveArraySort") +public fun DoubleArray.sort(): Unit { + noImpl +} + +/** + * Sorts the array in-place. + */ +@library("primitiveArraySort") +public fun FloatArray.sort(): Unit { + noImpl +} + +/** + * Sorts the array in-place. + */ +@library("primitiveArraySort") +public fun CharArray.sort(): Unit { + noImpl +} + +/** + * Sorts the array in-place according to the natural order of its elements. + */ +public fun > Array.sort(): Unit { + if (size > 1) + sort { a: T, b: T -> a.compareTo(b) } +} + +/** + * Sorts the array in-place according to the order specified by the given [comparator]. + */ +public fun Array.sortWith(comparator: Comparator): Unit { + if (size > 1) + sort { a, b -> comparator.compare(a, b) } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun ByteArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun ShortArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun IntArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun LongArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun FloatArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun DoubleArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun BooleanArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public fun CharArray.toTypedArray(): Array { + return copyOf().unsafeCast>() +} + /** * Sorts the array in-place according to the order specified by the given [comparison] function. */ diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index d0c9d80da7d..c9ba745e2f6 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -13205,6 +13205,293 @@ public inline fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray return java.util.Arrays.copyOfRange(this, fromIndex, toIndex) } +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun Array.plus(element: T): Array { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun ByteArray.plus(element: Byte): ByteArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun ShortArray.plus(element: Short): ShortArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun IntArray.plus(element: Int): IntArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun LongArray.plus(element: Long): LongArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun FloatArray.plus(element: Float): FloatArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun DoubleArray.plus(element: Double): DoubleArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun BooleanArray.plus(element: Boolean): BooleanArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public operator fun CharArray.plus(element: Char): CharArray { + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun Array.plus(elements: Collection): Array { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun ByteArray.plus(elements: Collection): ByteArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun ShortArray.plus(elements: Collection): ShortArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun IntArray.plus(elements: Collection): IntArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun LongArray.plus(elements: Collection): LongArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun FloatArray.plus(elements: Collection): FloatArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun DoubleArray.plus(elements: Collection): DoubleArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun BooleanArray.plus(elements: Collection): BooleanArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. + */ +public operator fun CharArray.plus(elements: Collection): CharArray { + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun Array.plus(elements: Array): Array { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun ByteArray.plus(elements: ByteArray): ByteArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun ShortArray.plus(elements: ShortArray): ShortArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun IntArray.plus(elements: IntArray): IntArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun LongArray.plus(elements: LongArray): LongArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun FloatArray.plus(elements: FloatArray): FloatArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public operator fun CharArray.plus(elements: CharArray): CharArray { + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +@kotlin.internal.InlineOnly +public inline fun Array.plusElement(element: T): Array { + return plus(element) +} + /** * Sorts the array in-place. */ @@ -13591,321 +13878,6 @@ public fun , R> Array<*>.filterIsInstanceTo(destinat return destination } -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun Array.plus(element: T): Array { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun ByteArray.plus(element: Byte): ByteArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun ShortArray.plus(element: Short): ShortArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun IntArray.plus(element: Int): IntArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun LongArray.plus(element: Long): LongArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun FloatArray.plus(element: Float): FloatArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun DoubleArray.plus(element: Double): DoubleArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun BooleanArray.plus(element: Boolean): BooleanArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -public operator fun CharArray.plus(element: Char): CharArray { - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun Array.plus(elements: Collection): Array { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun ByteArray.plus(elements: Collection): ByteArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun ShortArray.plus(elements: Collection): ShortArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun IntArray.plus(elements: Collection): IntArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun LongArray.plus(elements: Collection): LongArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun FloatArray.plus(elements: Collection): FloatArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun DoubleArray.plus(elements: Collection): DoubleArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun BooleanArray.plus(elements: Collection): BooleanArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] collection. - */ -@kotlin.jvm.JvmVersion -public operator fun CharArray.plus(elements: Collection): CharArray { - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun Array.plus(elements: Array): Array { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun ByteArray.plus(elements: ByteArray): ByteArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun ShortArray.plus(elements: ShortArray): ShortArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun IntArray.plus(elements: IntArray): IntArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun LongArray.plus(elements: LongArray): LongArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun FloatArray.plus(elements: FloatArray): FloatArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -@kotlin.jvm.JvmVersion -public operator fun CharArray.plus(elements: CharArray): CharArray { - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.jvm.JvmVersion -@kotlin.internal.InlineOnly -public inline fun Array.plusElement(element: T): Array { - return plus(element) -} - /** * Sorts the array in-place according to the natural order of its elements. * diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt index 28789944097..c59406991b3 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJS.kt @@ -21,69 +21,6 @@ import templates.Family.* fun specialJS(): List { val templates = arrayListOf() - - - templates add f("plusElement(element: T)") { - only(ArraysOfObjects) - returns("SELF") - returns(ArraysOfObjects) { "Array" } - inline(true) - annotations("""@Suppress("NOTHING_TO_INLINE")""") - doc { "Returns an array containing all elements of the original array and then the given [element]." } - body() { - """ - return this.asDynamic().concat(arrayOf(element)) - """ - } - } - - templates add f("plus(element: T)") { - operator(true) - - only(ArraysOfObjects, ArraysOfPrimitives) - returns("SELF") - returns(ArraysOfObjects) { "Array" } - inline(true) - annotations("""@Suppress("NOTHING_TO_INLINE")""") - doc { "Returns an array containing all elements of the original array and then the given [element]." } - body() { - """ - return this.asDynamic().concat(arrayOf(element)) - """ - } - } - - templates add f("plus(elements: Collection)") { - operator(true) - - only(ArraysOfObjects, ArraysOfPrimitives) - returns("SELF") - returns(ArraysOfObjects) { "Array" } - doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." } - body { - """ - return arrayPlusCollection(this, elements) - """ - } - } - - // This overload can cause nulls if array size is expanding, hence different return overload - templates add f("plus(elements: SELF)") { - operator(true) - - only(ArraysOfObjects, ArraysOfPrimitives) - doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." } - inline(true) - annotations("""@Suppress("NOTHING_TO_INLINE")""") - returns("SELF") - returns(ArraysOfObjects) { "Array" } - body { - """ - return this.asDynamic().concat(elements) - """ - } - } - templates add f("sort(noinline comparison: (T, T) -> Int)") { only(ArraysOfObjects, ArraysOfPrimitives) exclude(PrimitiveType.Boolean) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt index 4403cb1893b..8372e72ec35 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/SpecialJVM.kt @@ -21,65 +21,6 @@ import templates.Family.* fun specialJVM(): List { val templates = arrayListOf() - templates add f("plusElement(element: T)") { - inline(Inline.Only) - - only(InvariantArraysOfObjects) - returns("SELF") - doc { "Returns an array containing all elements of the original array and then the given [element]." } - body { "return plus(element)" } - } - - templates add f("plus(element: T)") { - operator(true) - - only(InvariantArraysOfObjects, ArraysOfPrimitives) - returns("SELF") - doc { "Returns an array containing all elements of the original array and then the given [element]." } - body() { - """ - val index = size - val result = java.util.Arrays.copyOf(this, index + 1) - result[index] = element - return result - """ - } - } - - templates add f("plus(elements: Collection)") { - operator(true) - - only(InvariantArraysOfObjects, ArraysOfPrimitives) - returns("SELF") - doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." } - body { - """ - var index = size - val result = java.util.Arrays.copyOf(this, index + elements.size) - for (element in elements) result[index++] = element - return result - """ - } - } - - templates add f("plus(elements: SELF)") { - operator(true) - - only(InvariantArraysOfObjects, ArraysOfPrimitives) - customSignature(InvariantArraysOfObjects) { "plus(elements: Array)" } - doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." } - returns("SELF") - body { - """ - val thisSize = size - val arraySize = elements.size - val result = java.util.Arrays.copyOf(this, thisSize + arraySize) - System.arraycopy(elements, 0, result, thisSize, arraySize) - return result - """ - } - } - templates add f("fill(element: T, fromIndex: Int = 0, toIndex: Int = size)") { only(InvariantArraysOfObjects, ArraysOfPrimitives) doc { "Fills original array with the provided value." } @@ -214,7 +155,111 @@ fun specialJVM(): List { } object CommonArrays { - // TODO: plus + + fun f_plusElement() = f("plusElement(element: T)") { + inline(Platform.JVM, Inline.Only) + inline(Platform.JS, Inline.Yes) + annotations(Platform.JS, """@Suppress("NOTHING_TO_INLINE")""") + + only(InvariantArraysOfObjects) + only(Platform.JS, ArraysOfObjects) + + returns("SELF") + returns(Platform.JS, ArraysOfObjects) { "Array" } + doc { "Returns an array containing all elements of the original array and then the given [element]." } + body(Platform.JVM) { "return plus(element)" } + body(Platform.JS) { + """ + return this.asDynamic().concat(arrayOf(element)) + """ + } + } + + fun f_plusElementOperator() = f("plus(element: T)") { + operator(true) + + inline(Platform.JS, Inline.Yes) + annotations(Platform.JS, """@Suppress("NOTHING_TO_INLINE")""") + + only(InvariantArraysOfObjects, ArraysOfPrimitives) + only(Platform.JS, ArraysOfObjects, ArraysOfPrimitives) + + returns("SELF") + returns(Platform.JS, ArraysOfObjects) { "Array" } + doc { "Returns an array containing all elements of the original array and then the given [element]." } + body(Platform.JVM) { + """ + val index = size + val result = java.util.Arrays.copyOf(this, index + 1) + result[index] = element + return result + """ + } + body(Platform.JS) { + """ + return this.asDynamic().concat(arrayOf(element)) + """ + } + } + + fun f_plusCollection() = f("plus(elements: Collection)") { + operator(true) + + // TODO: inline arrayPlusCollection when @PublishedAPI is available +// inline(Platform.JS, Inline.Yes) +// annotations(Platform.JS, """@Suppress("NOTHING_TO_INLINE")""") + + only(InvariantArraysOfObjects, ArraysOfPrimitives) + only(Platform.JS, ArraysOfObjects, ArraysOfPrimitives) + + returns("SELF") + returns(Platform.JS, ArraysOfObjects) { "Array" } + doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] collection." } + body(Platform.JVM) { + """ + var index = size + val result = java.util.Arrays.copyOf(this, index + elements.size) + for (element in elements) result[index++] = element + return result + """ + } + body(Platform.JS) { + """ + return arrayPlusCollection(this, elements) + """ + } + } + + fun f_plusArray() = f("plus(elements: SELF)") { + operator(true) + + inline(Platform.JS, Inline.Yes) + annotations(Platform.JS, """@Suppress("NOTHING_TO_INLINE")""") + + only(InvariantArraysOfObjects, ArraysOfPrimitives) + only(Platform.JS, ArraysOfObjects, ArraysOfPrimitives) + customSignature(InvariantArraysOfObjects) { "plus(elements: Array)" } + + doc { "Returns an array containing all elements of the original array and then all elements of the given [elements] array." } + returns("SELF") + returns(Platform.JS, ArraysOfObjects) { "Array" } + + body(Platform.JVM) { + """ + val thisSize = size + val arraySize = elements.size + val result = java.util.Arrays.copyOf(this, thisSize + arraySize) + System.arraycopy(elements, 0, result, thisSize, arraySize) + return result + """ + } + body(Platform.JS) { + """ + return this.asDynamic().concat(elements) + """ + } + } + fun f_copyOfRange() = f("copyOfRange(fromIndex: Int, toIndex: Int)") { inline(Platform.JVM, Inline.Only) inline(Platform.JS, Inline.Yes) @@ -414,6 +459,7 @@ object CommonArrays { // TODO: use reflection later to get all functions of matching type fun templates() = + listOf(f_plusElement(), f_plusElementOperator(), f_plusCollection(), f_plusArray()) + listOf(f_copyOf(), f_copyOfRange()) + f_copyOfResized() + f_sortPrimitives() +