From c4abd93f53308a0ed0c90860ea5d33e1cf0cc3f1 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Tue, 25 Dec 2018 19:23:57 +0300 Subject: [PATCH] Regenerate actual implementations with runtime:generator The functions where implementations were significantly changed: - toTypedArray - contentToString --- .../main/kotlin/generated/_ArraysNative.kt | 1482 +++++++++++++++++ .../kotlin/generated/_CollectionsNative.kt | 28 + .../_ComparisonsNative.kt} | 73 +- .../main/kotlin/kotlin/collections/Arrays.kt | 1422 +--------------- .../kotlin/kotlin/collections/Collections.kt | 138 -- 5 files changed, 1550 insertions(+), 1593 deletions(-) create mode 100644 runtime/src/main/kotlin/generated/_ArraysNative.kt create mode 100644 runtime/src/main/kotlin/generated/_CollectionsNative.kt rename runtime/src/main/kotlin/{kotlin/comparisons/Comparisons.kt => generated/_ComparisonsNative.kt} (66%) diff --git a/runtime/src/main/kotlin/generated/_ArraysNative.kt b/runtime/src/main/kotlin/generated/_ArraysNative.kt new file mode 100644 index 00000000000..112d5ead714 --- /dev/null +++ b/runtime/src/main/kotlin/generated/_ArraysNative.kt @@ -0,0 +1,1482 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package kotlin.collections + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun Array.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: T): Boolean = this@asList.contains(element) + override fun get(index: Int): T = this@asList[index] + override fun indexOf(element: T): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: T): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun ByteArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Byte): Boolean = this@asList.contains(element) + override fun get(index: Int): Byte = this@asList[index] + override fun indexOf(element: Byte): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Byte): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun ShortArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Short): Boolean = this@asList.contains(element) + override fun get(index: Int): Short = this@asList[index] + override fun indexOf(element: Short): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Short): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun IntArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Int): Boolean = this@asList.contains(element) + override fun get(index: Int): Int = this@asList[index] + override fun indexOf(element: Int): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Int): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun LongArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Long): Boolean = this@asList.contains(element) + override fun get(index: Int): Long = this@asList[index] + override fun indexOf(element: Long): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Long): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun FloatArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Float): Boolean = this@asList.contains(element) + override fun get(index: Int): Float = this@asList[index] + override fun indexOf(element: Float): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Float): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun DoubleArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Double): Boolean = this@asList.contains(element) + override fun get(index: Int): Double = this@asList[index] + override fun indexOf(element: Double): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Double): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun BooleanArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Boolean): Boolean = this@asList.contains(element) + override fun get(index: Int): Boolean = this@asList[index] + override fun indexOf(element: Boolean): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Boolean): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns a [List] that wraps the original array. + */ +public actual fun CharArray.asList(): List { + return object : AbstractList(), RandomAccess { + override val size: Int get() = this@asList.size + override fun isEmpty(): Boolean = this@asList.isEmpty() + override fun contains(element: Char): Boolean = this@asList.contains(element) + override fun get(index: Int): Char = this@asList[index] + override fun indexOf(element: Char): Int = this@asList.indexOf(element) + override fun lastIndexOf(element: Char): Int = this@asList.lastIndexOf(element) + } +} + +/** + * Returns `true` if the two specified arrays are *deeply* equal to one another, + * i.e. contain the same number of the same elements in the same order. + * + * If two corresponding elements are nested arrays, they are also compared deeply. + * If any of arrays contains itself on any nesting level the behavior is undefined. + */ +@SinceKotlin("1.1") +public actual infix fun Array.contentDeepEquals(other: Array): Boolean { + return contentDeepEqualsImpl(other) +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + * Nested arrays are treated as lists too. + * + * If any of arrays contains itself on any nesting level the behavior is undefined. + */ +@SinceKotlin("1.1") +public actual fun Array.contentDeepHashCode(): Int { + return contentDeepHashCodeImpl() +} + +/** + * Returns a string representation of the contents of this array as if it is a [List]. + * Nested arrays are treated as lists too. + * + * If any of arrays contains itself on any nesting level that reference + * is rendered as `"[...]"` to prevent recursion. + * + * @sample samples.collections.Arrays.ContentOperations.contentDeepToString + */ +@SinceKotlin("1.1") +public actual fun Array.contentDeepToString(): String { + return contentDeepToStringImpl() +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun Array.contentEquals(other: Array): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns `true` if the two specified arrays are *structurally* equal to one another, + * i.e. contain the same number of the same elements in the same order. + */ +@SinceKotlin("1.1") +public actual infix fun CharArray.contentEquals(other: CharArray): Boolean { + if (this === other) { + return true + } + if (size != other.size) { + return false + } + for (i in indices) { + if (this[i] != other[i]) { + return false + } + } + return true +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun Array.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun ByteArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun ShortArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun IntArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun LongArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun FloatArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun DoubleArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun BooleanArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a hash code based on the contents of this array as if it is [List]. + */ +@SinceKotlin("1.1") +public actual fun CharArray.contentHashCode(): Int { + var result = 1 + for (element in this) + result = 31 * result + element.hashCode() + return result +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun Array.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun ByteArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun ShortArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun IntArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun LongArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun FloatArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun DoubleArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun BooleanArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Returns a string representation of the contents of the specified array as if it is [List]. + * + * @sample samples.collections.Arrays.ContentOperations.contentToString + */ +@SinceKotlin("1.1") +public actual fun CharArray.contentToString(): String { + return joinToString(", ", "[", "]") +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun Array.copyInto(destination: Array, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): Array { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ByteArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): ShortArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun IntArray.copyInto(destination: IntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): IntArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun LongArray.copyInto(destination: LongArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): LongArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): FloatArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): DoubleArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): BooleanArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Copies this array or its subrange into the [destination] array and returns that array. + * + * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. + * + * @param destination the array to copy to. + * @param destinationOffset the position in the [destination] array to copy to, 0 by default. + * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. + * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. + * + * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. + * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], + * or when that index is out of the [destination] array indices range. + * + * @return the [destination] array. + */ +@SinceKotlin("1.3") +@Suppress("ACTUAL_FUNCTION_WITH_DEFAULT_ARGUMENTS") +public actual fun CharArray.copyInto(destination: CharArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size): CharArray { + this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) + return destination +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun Array.copyOf(): Array { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun ByteArray.copyOf(): ByteArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun ShortArray.copyOf(): ShortArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun IntArray.copyOf(): IntArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun LongArray.copyOf(): LongArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun FloatArray.copyOf(): FloatArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun DoubleArray.copyOf(): DoubleArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun BooleanArray.copyOf(): BooleanArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array. + * + * @sample samples.collections.Arrays.CopyOfOperations.copyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun CharArray.copyOf(): CharArray { + return this.copyOfUninitializedElements(size) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with zero values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun ByteArray.copyOf(newSize: Int): ByteArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with zero values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun ShortArray.copyOf(newSize: Int): ShortArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with zero values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun IntArray.copyOf(newSize: Int): IntArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with zero values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun LongArray.copyOf(newSize: Int): LongArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with zero values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun FloatArray.copyOf(newSize: Int): FloatArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with zero values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun DoubleArray.copyOf(newSize: Int): DoubleArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with `false` values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with `false` values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun BooleanArray.copyOf(newSize: Int): BooleanArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with null char (`\u0000`) values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with null char (`\u0000`) values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun CharArray.copyOf(newSize: Int): CharArray { + return this.copyOfUninitializedElements(newSize) +} + +/** + * Returns new array which is a copy of the original array, resized to the given [newSize]. + * The copy is either truncated or padded at the end with `null` values if necessary. + * + * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. + * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with `null` values. + * + * @sample samples.collections.Arrays.CopyOfOperations.resizingCopyOf + */ +@kotlin.internal.InlineOnly +public actual inline fun Array.copyOf(newSize: Int): Array { + return this.copyOfNulls(newSize) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun Array.copyOfRange(fromIndex: Int, toIndex: Int): Array { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns a new array which is a copy of the specified range of the original array. + * + * @param fromIndex the start of the range (inclusive), must be in `0..array.size` + * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` + */ +@kotlin.internal.InlineOnly +public actual inline fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray { + checkCopyOfRangeArguments(fromIndex, toIndex, size) + return copyOfUninitializedElements(fromIndex, toIndex) +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun Array.plus(element: T): Array { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun ByteArray.plus(element: Byte): ByteArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun ShortArray.plus(element: Short): ShortArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun IntArray.plus(element: Int): IntArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun LongArray.plus(element: Long): LongArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun FloatArray.plus(element: Float): FloatArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun DoubleArray.plus(element: Double): DoubleArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun BooleanArray.plus(element: Boolean): BooleanArray { + val index = size + val result = copyOfUninitializedElements(index + 1) + result[index] = element + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +public actual operator fun CharArray.plus(element: Char): CharArray { + val index = size + val result = copyOfUninitializedElements(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 actual operator fun Array.plus(elements: Collection): Array { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun ByteArray.plus(elements: Collection): ByteArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun ShortArray.plus(elements: Collection): ShortArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun IntArray.plus(elements: Collection): IntArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun LongArray.plus(elements: Collection): LongArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun FloatArray.plus(elements: Collection): FloatArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun DoubleArray.plus(elements: Collection): DoubleArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun BooleanArray.plus(elements: Collection): BooleanArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun CharArray.plus(elements: Collection): CharArray { + var index = size + val result = copyOfUninitializedElements(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 actual operator fun Array.plus(elements: Array): Array { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun ByteArray.plus(elements: ByteArray): ByteArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun ShortArray.plus(elements: ShortArray): ShortArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun IntArray.plus(elements: IntArray): IntArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun LongArray.plus(elements: LongArray): LongArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun FloatArray.plus(elements: FloatArray): FloatArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then all elements of the given [elements] array. + */ +public actual operator fun CharArray.plus(elements: CharArray): CharArray { + val thisSize = size + val arraySize = elements.size + val result = copyOfUninitializedElements(thisSize + arraySize) + elements.copyRangeTo(result, 0, arraySize, thisSize) + return result +} + +/** + * Returns an array containing all elements of the original array and then the given [element]. + */ +@kotlin.internal.InlineOnly +public actual inline fun Array.plusElement(element: T): Array { + return plus(element) +} + +/** + * Sorts the array in-place. + */ +public actual fun IntArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place. + */ +public actual fun LongArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place. + */ +public actual fun ByteArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place. + */ +public actual fun ShortArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place. + */ +public actual fun DoubleArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place. + */ +public actual fun FloatArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place. + */ +public actual fun CharArray.sort(): Unit { + if (size > 1) kotlin.util.sortArray(this) +} + +/** + * Sorts the array in-place according to the natural order of its elements. + */ +public actual fun > Array.sort(): Unit { + if (size > 1) kotlin.util.sortArrayComparable(this) +} + +/** + * Sorts the array in-place according to the order specified by the given [comparator]. + */ +public actual fun Array.sortWith(comparator: Comparator): Unit { + if (size > 1) kotlin.util.sortArrayWith(this, 0, size, comparator) +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun ByteArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun ShortArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun IntArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun LongArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun FloatArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun DoubleArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun BooleanArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + +/** + * Returns a *typed* object array containing all of the elements of this primitive array. + */ +public actual fun CharArray.toTypedArray(): Array { + return Array(size) { index -> this[index] } +} + diff --git a/runtime/src/main/kotlin/generated/_CollectionsNative.kt b/runtime/src/main/kotlin/generated/_CollectionsNative.kt new file mode 100644 index 00000000000..4425c54825f --- /dev/null +++ b/runtime/src/main/kotlin/generated/_CollectionsNative.kt @@ -0,0 +1,28 @@ +/* + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. + */ + +package kotlin.collections + +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + + +/** + * Reverses elements in the list in-place. + */ +public actual fun MutableList.reverse(): Unit { + val midPoint = (size / 2) - 1 + if (midPoint < 0) return + var reverseIndex = lastIndex + for (index in 0..midPoint) { + val tmp = this[index] + this[index] = this[reverseIndex] + this[reverseIndex] = tmp + reverseIndex-- + } +} + diff --git a/runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt b/runtime/src/main/kotlin/generated/_ComparisonsNative.kt similarity index 66% rename from runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt rename to runtime/src/main/kotlin/generated/_ComparisonsNative.kt index 64bc8d2f563..507c0f8a9f3 100644 --- a/runtime/src/main/kotlin/kotlin/comparisons/Comparisons.kt +++ b/runtime/src/main/kotlin/generated/_ComparisonsNative.kt @@ -1,18 +1,22 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license - * that can be found in the LICENSE file. + * Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the license/LICENSE.txt file. */ package kotlin.comparisons -// Implements expects from _Comparisions.kt. +// +// NOTE: THIS FILE IS AUTO-GENERATED by the GenerateStandardLib.kt +// See: https://github.com/JetBrains/kotlin/tree/master/libraries/stdlib +// + /** * Returns the greater of two values. * If values are equal, returns the first one. */ @SinceKotlin("1.1") -public actual fun > maxOf(a: T, b: T): T { +public actual fun > maxOf(a: T, b: T): T { return if (a >= b) a else b } @@ -21,7 +25,7 @@ public actual fun > maxOf(a: T, b: T): T { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Byte, b: Byte): Byte { +public actual inline fun maxOf(a: Byte, b: Byte): Byte { return maxOf(a.toInt(), b.toInt()).toByte() } @@ -30,7 +34,7 @@ public inline actual fun maxOf(a: Byte, b: Byte): Byte { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Short, b: Short): Short { +public actual inline fun maxOf(a: Short, b: Short): Short { return maxOf(a.toInt(), b.toInt()).toShort() } @@ -39,7 +43,7 @@ public inline actual fun maxOf(a: Short, b: Short): Short { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Int, b: Int): Int { +public actual inline fun maxOf(a: Int, b: Int): Int { return if (a >= b) a else b } @@ -48,7 +52,7 @@ public inline actual fun maxOf(a: Int, b: Int): Int { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Long, b: Long): Long { +public actual inline fun maxOf(a: Long, b: Long): Long { return if (a >= b) a else b } @@ -57,9 +61,7 @@ public inline actual fun maxOf(a: Long, b: Long): Long { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Float, b: Float): Float { - // According to http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#max-float-float- - // return NaN if one of the args is NaN. +public actual inline fun maxOf(a: Float, b: Float): Float { // TODO: Check +/-0.0 return when { a.isNaN() -> a @@ -73,7 +75,8 @@ public inline actual fun maxOf(a: Float, b: Float): Float { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Double, b: Double): Double { +public actual inline fun maxOf(a: Double, b: Double): Double { + // TODO: Check +/-0.0 return when { a.isNaN() -> a b.isNaN() -> b @@ -85,7 +88,7 @@ public inline actual fun maxOf(a: Double, b: Double): Double { * Returns the greater of three values. */ @SinceKotlin("1.1") -public actual fun > maxOf(a: T, b: T, c: T): T { +public actual fun > maxOf(a: T, b: T, c: T): T { return maxOf(a, maxOf(b, c)) } @@ -94,7 +97,7 @@ public actual fun > maxOf(a: T, b: T, c: T): T { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Byte, b: Byte, c: Byte): Byte { +public actual inline fun maxOf(a: Byte, b: Byte, c: Byte): Byte { return maxOf(a.toInt(), maxOf(b.toInt(), c.toInt())).toByte() } @@ -103,7 +106,7 @@ public inline actual fun maxOf(a: Byte, b: Byte, c: Byte): Byte { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Short, b: Short, c: Short): Short { +public actual inline fun maxOf(a: Short, b: Short, c: Short): Short { return maxOf(a.toInt(), maxOf(b.toInt(), c.toInt())).toShort() } @@ -112,7 +115,7 @@ public inline actual fun maxOf(a: Short, b: Short, c: Short): Short { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Int, b: Int, c: Int): Int { +public actual inline fun maxOf(a: Int, b: Int, c: Int): Int { return maxOf(a, maxOf(b, c)) } @@ -121,7 +124,7 @@ public inline actual fun maxOf(a: Int, b: Int, c: Int): Int { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Long, b: Long, c: Long): Long { +public actual inline fun maxOf(a: Long, b: Long, c: Long): Long { return maxOf(a, maxOf(b, c)) } @@ -130,7 +133,7 @@ public inline actual fun maxOf(a: Long, b: Long, c: Long): Long { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Float, b: Float, c: Float): Float { +public actual inline fun maxOf(a: Float, b: Float, c: Float): Float { return maxOf(a, maxOf(b, c)) } @@ -139,7 +142,7 @@ public inline actual fun maxOf(a: Float, b: Float, c: Float): Float { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun maxOf(a: Double, b: Double, c: Double): Double { +public actual inline fun maxOf(a: Double, b: Double, c: Double): Double { return maxOf(a, maxOf(b, c)) } @@ -148,7 +151,7 @@ public inline actual fun maxOf(a: Double, b: Double, c: Double): Double { * If values are equal, returns the first one. */ @SinceKotlin("1.1") -public actual fun > minOf(a: T, b: T): T { +public actual fun > minOf(a: T, b: T): T { return if (a <= b) a else b } @@ -157,7 +160,7 @@ public actual fun > minOf(a: T, b: T): T { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Byte, b: Byte): Byte { +public actual inline fun minOf(a: Byte, b: Byte): Byte { return minOf(a.toInt(), b.toInt()).toByte() } @@ -166,7 +169,7 @@ public inline actual fun minOf(a: Byte, b: Byte): Byte { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Short, b: Short): Short { +public actual inline fun minOf(a: Short, b: Short): Short { return minOf(a.toInt(), b.toInt()).toShort() } @@ -175,7 +178,7 @@ public inline actual fun minOf(a: Short, b: Short): Short { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Int, b: Int): Int { +public actual inline fun minOf(a: Int, b: Int): Int { return if (a <= b) a else b } @@ -184,7 +187,7 @@ public inline actual fun minOf(a: Int, b: Int): Int { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Long, b: Long): Long { +public actual inline fun minOf(a: Long, b: Long): Long { return if (a <= b) a else b } @@ -193,9 +196,8 @@ public inline actual fun minOf(a: Long, b: Long): Long { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Float, b: Float): Float { - // According to http://docs.oracle.com/javase/8/docs/api/java/lang/Math.html#min-float-float- - // return NaN if one of the args is NaN. +public actual inline fun minOf(a: Float, b: Float): Float { + // TODO: Check +/-0.0 return when { a.isNaN() -> a b.isNaN() -> b @@ -208,7 +210,8 @@ public inline actual fun minOf(a: Float, b: Float): Float { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Double, b: Double): Double { +public actual inline fun minOf(a: Double, b: Double): Double { + // TODO: Check +/-0.0 return when { a.isNaN() -> a b.isNaN() -> b @@ -220,7 +223,7 @@ public inline actual fun minOf(a: Double, b: Double): Double { * Returns the smaller of three values. */ @SinceKotlin("1.1") -public actual fun > minOf(a: T, b: T, c: T): T { +public actual fun > minOf(a: T, b: T, c: T): T { return minOf(a, minOf(b, c)) } @@ -229,7 +232,7 @@ public actual fun > minOf(a: T, b: T, c: T): T { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Byte, b: Byte, c: Byte): Byte { +public actual inline fun minOf(a: Byte, b: Byte, c: Byte): Byte { return minOf(a.toInt(), minOf(b.toInt(), c.toInt())).toByte() } @@ -238,7 +241,7 @@ public inline actual fun minOf(a: Byte, b: Byte, c: Byte): Byte { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Short, b: Short, c: Short): Short { +public actual inline fun minOf(a: Short, b: Short, c: Short): Short { return minOf(a.toInt(), minOf(b.toInt(), c.toInt())).toShort() } @@ -247,7 +250,7 @@ public inline actual fun minOf(a: Short, b: Short, c: Short): Short { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Int, b: Int, c: Int): Int { +public actual inline fun minOf(a: Int, b: Int, c: Int): Int { return minOf(a, minOf(b, c)) } @@ -256,7 +259,7 @@ public inline actual fun minOf(a: Int, b: Int, c: Int): Int { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Long, b: Long, c: Long): Long { +public actual inline fun minOf(a: Long, b: Long, c: Long): Long { return minOf(a, minOf(b, c)) } @@ -265,7 +268,7 @@ public inline actual fun minOf(a: Long, b: Long, c: Long): Long { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Float, b: Float, c: Float): Float { +public actual inline fun minOf(a: Float, b: Float, c: Float): Float { return minOf(a, minOf(b, c)) } @@ -274,7 +277,7 @@ public inline actual fun minOf(a: Float, b: Float, c: Float): Float { */ @SinceKotlin("1.1") @kotlin.internal.InlineOnly -public inline actual fun minOf(a: Double, b: Double, c: Double): Double { +public actual inline fun minOf(a: Double, b: Double, c: Double): Double { return minOf(a, minOf(b, c)) } diff --git a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt index 6d667ffe5ed..8fef2f9b868 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Arrays.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Arrays.kt @@ -15,203 +15,6 @@ import kotlin.util.sortArray /** Returns the array if it's not `null`, or an empty array otherwise. */ public actual inline fun Array?.orEmpty(): Array = this ?: emptyArray() -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun Array.copyOf(): Array { - return this.copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun ByteArray.copyOf(): ByteArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun ShortArray.copyOf(): ShortArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun IntArray.copyOf(): IntArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun LongArray.copyOf(): LongArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun FloatArray.copyOf(): FloatArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun DoubleArray.copyOf(): DoubleArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun BooleanArray.copyOf(): BooleanArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array. - */ -@kotlin.internal.InlineOnly -public actual inline fun CharArray.copyOf(): CharArray { - return copyOfUninitializedElements(size) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with `null` values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with `null` values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizingCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun Array.copyOf(newSize: Int): Array { - return copyOfNulls(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with zero values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun ByteArray.copyOf(newSize: Int): ByteArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with zero values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun ShortArray.copyOf(newSize: Int): ShortArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with zero values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun IntArray.copyOf(newSize: Int): IntArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with zero values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun LongArray.copyOf(newSize: Int): LongArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with zero values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun FloatArray.copyOf(newSize: Int): FloatArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with zero values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with zero values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun DoubleArray.copyOf(newSize: Int): DoubleArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with `false` values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with `false` values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun BooleanArray.copyOf(newSize: Int): BooleanArray { - return copyOfUninitializedElements(newSize) -} - -/** - * Returns new array which is a copy of the original array, resized to the given [newSize]. - * The copy is either truncated or padded at the end with null char (`\u0000`) values if necessary. - * - * - If [newSize] is less than the size of the original array, the copy array is truncated to the [newSize]. - * - If [newSize] is greater than the size of the original array, the extra elements in the copy array are filled with null char (`\u0000`) values. - * - * @sample samples.collections.Arrays.CopyOfOperations.resizedPrimitiveCopyOf - */ -@kotlin.internal.InlineOnly -public actual inline fun CharArray.copyOf(newSize: Int): CharArray { - return copyOfUninitializedElements(newSize) -} @PublishedApi internal inline fun checkCopyOfRangeArguments(fromIndex: Int, toIndex: Int, size: Int) { if (toIndex > size) @@ -220,451 +23,13 @@ public actual inline fun CharArray.copyOf(newSize: Int): CharArray { throw IllegalArgumentException("fromIndex ($fromIndex) is greater than toIndex ($toIndex).") } -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -// TODO: The method may check input or return Array. -// Now we check its input (fromIndex <= toIndex < size). -// Sync its behaviour wiht Kotlin JVM when the problem is solved there. -@kotlin.internal.InlineOnly -public actual inline fun Array.copyOfRange(fromIndex: Int, toIndex: Int): Array { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun ByteArray.copyOfRange(fromIndex: Int, toIndex: Int): ByteArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun ShortArray.copyOfRange(fromIndex: Int, toIndex: Int): ShortArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun IntArray.copyOfRange(fromIndex: Int, toIndex: Int): IntArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun LongArray.copyOfRange(fromIndex: Int, toIndex: Int): LongArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun FloatArray.copyOfRange(fromIndex: Int, toIndex: Int): FloatArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun DoubleArray.copyOfRange(fromIndex: Int, toIndex: Int): DoubleArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun BooleanArray.copyOfRange(fromIndex: Int, toIndex: Int): BooleanArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Returns a new array which is a copy of the specified range of the original array. - * - * @param fromIndex the start of the range (inclusive), must be in `0..array.size` - * @param toIndex the end of the range (exclusive), must be in `fromIndex..array.size` - */ -@kotlin.internal.InlineOnly -public actual inline fun CharArray.copyOfRange(fromIndex: Int, toIndex: Int): CharArray { - checkCopyOfRangeArguments(fromIndex, toIndex, size) - return copyOfUninitializedElements(fromIndex, toIndex) -} - -/** - * Sorts the array in-place according to the order specified by the given [comparator]. - */ -public actual fun Array.sortWith(comparator: Comparator): Unit { - if (size > 1) sortArrayWith(this, 0, size, comparator) -} - -/** - * Sorts the array in-place according to the natural order of its elements. - */ -public actual fun > Array.sort(): Unit { - if (size > 1) sortArrayComparable(this) -} public fun Array.sortWith(comparator: Comparator, fromIndex: Int = 0, toIndex: Int = size): Unit { sortArrayWith(this, fromIndex, toIndex, comparator) } -/** - * Sorts the array in-place. - */ -public actual fun IntArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Sorts the array in-place. - */ -public actual fun LongArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Sorts the array in-place. - */ -public actual fun ByteArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Sorts the array in-place. - */ -public actual fun ShortArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Sorts the array in-place. - */ -public actual fun DoubleArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Sorts the array in-place. - */ -public actual fun FloatArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Sorts the array in-place. - */ -public actual fun CharArray.sort(): Unit { - if (size > 1) sortArray(this) -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun ByteArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun ShortArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun IntArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun LongArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun FloatArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun DoubleArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun BooleanArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - -/** - * Returns a *typed* object array containing all of the elements of this primitive array. - */ -public actual fun CharArray.toTypedArray(): Array { - val result = arrayOfNulls(size) - for (index in indices) - result[index] = this[index] - @Suppress("UNCHECKED_CAST") - return result as Array -} - - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -@kotlin.internal.InlineOnly -public actual inline fun Array.contentToString(): String { - return this.subarrayContentToString(offset = 0, length = this.size) -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun ByteArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun ShortArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun IntArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun LongArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun FloatArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun DoubleArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun BooleanArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - -/** - * Returns a string representation of the contents of the specified array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun CharArray.contentToString(): String { - if (size == 0) - return "[]" - val iMax = size - 1 - - val b = StringBuilder() - b.append('[') - var i = 0 - while (true) { - b.append(this[i]) - if (i == iMax) - return b.append(']').toString() - b.append(", ") - i++ - } -} - +// TODO: internal /** * Returns a string representation of the contents of the subarray of the specified array as if it is [List]. */ @@ -683,213 +48,6 @@ public inline fun Array.subarrayContentToString(offset: Int, length: return sb.toString() } -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun Array.copyInto(destination: Array, destinationOffset: Int, startIndex: Int, endIndex: Int): Array { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun ByteArray.copyInto(destination: ByteArray, destinationOffset: Int, startIndex: Int, endIndex: Int): ByteArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun ShortArray.copyInto(destination: ShortArray, destinationOffset: Int, startIndex: Int, endIndex: Int): ShortArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun IntArray.copyInto(destination: IntArray, destinationOffset: Int, startIndex: Int, endIndex: Int): IntArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun LongArray.copyInto(destination: LongArray, destinationOffset: Int, startIndex: Int, endIndex: Int): LongArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun FloatArray.copyInto(destination: FloatArray, destinationOffset: Int, startIndex: Int, endIndex: Int): FloatArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun DoubleArray.copyInto(destination: DoubleArray, destinationOffset: Int, startIndex: Int, endIndex: Int): DoubleArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun BooleanArray.copyInto(destination: BooleanArray, destinationOffset: Int, startIndex: Int, endIndex: Int): BooleanArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Copies this array or its subrange into the [destination] array and returns that array. - * - * It's allowed to pass the same array in the [destination] and even specify the subrange so that it overlaps with the destination range. - * - * @param destination the array to copy to. - * @param destinationOffset the position in the [destination] array to copy to, 0 by default. - * @param startIndex the beginning (inclusive) of the subrange to copy, 0 by default. - * @param endIndex the end (exclusive) of the subrange to copy, size of this array by default. - * - * @throws IndexOutOfBoundsException or [IllegalArgumentException] when [startIndex] or [endIndex] is out of range of this array indices or when `startIndex > endIndex`. - * @throws IndexOutOfBoundsException when the subrange doesn't fit into the [destination] array starting at the specified [destinationOffset], - * or when that index is out of the [destination] array indices range. - * - * @return the [destination] array. - */ -@SinceKotlin("1.3") -public actual fun CharArray.copyInto(destination: CharArray, destinationOffset: Int, startIndex: Int, endIndex: Int): CharArray { - this.copyRangeTo(destination, startIndex, endIndex, destinationOffset) - return destination -} - -/** - * Returns `true` if the two specified arrays are *deeply* equal to one another, - * i.e. contain the same number of the same elements in the same order. - * - * If two corresponding elements are nested arrays, they are also compared deeply. - * If any of arrays contains itself on any nesting level the behavior is undefined. - */ -@SinceKotlin("1.1") -public actual infix fun Array.contentDeepEquals(other: Array): Boolean = contentDeepEqualsImpl(other) /** * Returns a hash code based on the contents of this array as if it is [List]. @@ -899,7 +57,7 @@ public actual infix fun Array.contentDeepEquals(other: Array): */ @SinceKotlin("1.1") @UseExperimental(ExperimentalUnsignedTypes::class) -public actual fun Array.contentDeepHashCode(): Int { +internal fun Array.contentDeepHashCodeImpl(): Int { var result = 1 for (element in this) { val elementHash = when (element) { @@ -929,295 +87,6 @@ public actual fun Array.contentDeepHashCode(): Int { return result } -/** - * Returns a string representation of the contents of this array as if it is a [List]. - * Nested arrays are treated as lists too. - * - * If any of arrays contains itself on any nesting level that reference - * is rendered as `"[...]"` to prevent recursion. - */ -@SinceKotlin("1.1") -public actual fun Array.contentDeepToString(): String = contentDeepToStringImpl() - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun Array.contentEquals(other: Array): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun ByteArray.contentEquals(other: ByteArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun ShortArray.contentEquals(other: ShortArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun IntArray.contentEquals(other: IntArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun LongArray.contentEquals(other: LongArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun FloatArray.contentEquals(other: FloatArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun DoubleArray.contentEquals(other: DoubleArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun BooleanArray.contentEquals(other: BooleanArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns `true` if the two specified arrays are *structurally* equal to one another, - * i.e. contain the same number of the same elements in the same order. - */ -@SinceKotlin("1.1") -public actual infix fun CharArray.contentEquals(other: CharArray): Boolean { - if (this === other) { - return true - } - if (size != other.size) { - return false - } - for (i in indices) { - if (this[i] != other[i]) { - return false - } - } - return true -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun Array.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + (element?.hashCode() ?: 0) - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun ByteArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun ShortArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun IntArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun LongArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun FloatArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun DoubleArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun BooleanArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - -/** - * Returns a hash code based on the contents of this array as if it is [List]. - */ -@SinceKotlin("1.1") -public actual fun CharArray.contentHashCode(): Int { - var result = 1 - for (element in this) - result = 31 * result + element.hashCode() - return result -} - internal actual fun arrayOfNulls(reference: Array, size: Int): Array { return (@Suppress("UNCHECKED_CAST")(arrayOfNulls(size)) as Array) } @@ -1259,290 +128,3 @@ public actual inline fun Collection.toTypedArray(): Array { @Suppress("UNCHECKED_CAST") return result as Array } - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun Array.plus(element: T): Array { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun ByteArray.plus(element: Byte): ByteArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun ShortArray.plus(element: Short): ShortArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun IntArray.plus(element: Int): IntArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun LongArray.plus(element: Long): LongArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun FloatArray.plus(element: Float): FloatArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun DoubleArray.plus(element: Double): DoubleArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun BooleanArray.plus(element: Boolean): BooleanArray { - val index = size - val result = copyOfUninitializedElements(index + 1) - result[index] = element - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -public actual operator fun CharArray.plus(element: Char): CharArray { - val index = size - val result = copyOfUninitializedElements(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 actual operator fun Array.plus(elements: Collection): Array { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun ByteArray.plus(elements: Collection): ByteArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun ShortArray.plus(elements: Collection): ShortArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun IntArray.plus(elements: Collection): IntArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun LongArray.plus(elements: Collection): LongArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun FloatArray.plus(elements: Collection): FloatArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun DoubleArray.plus(elements: Collection): DoubleArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun BooleanArray.plus(elements: Collection): BooleanArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun CharArray.plus(elements: Collection): CharArray { - var index = size - val result = copyOfUninitializedElements(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 actual operator fun Array.plus(elements: Array): Array { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun ByteArray.plus(elements: ByteArray): ByteArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun ShortArray.plus(elements: ShortArray): ShortArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun IntArray.plus(elements: IntArray): IntArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun LongArray.plus(elements: LongArray): LongArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun FloatArray.plus(elements: FloatArray): FloatArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun DoubleArray.plus(elements: DoubleArray): DoubleArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun BooleanArray.plus(elements: BooleanArray): BooleanArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then all elements of the given [elements] array. - */ -public actual operator fun CharArray.plus(elements: CharArray): CharArray { - val thisSize = size - val arraySize = elements.size - val result = copyOfUninitializedElements(thisSize + arraySize) - elements.copyRangeTo(result, 0, arraySize, thisSize) - return result -} - -/** - * Returns an array containing all elements of the original array and then the given [element]. - */ -@kotlin.internal.InlineOnly -public actual inline fun Array.plusElement(element: T): Array { - return plus(element) -} diff --git a/runtime/src/main/kotlin/kotlin/collections/Collections.kt b/runtime/src/main/kotlin/kotlin/collections/Collections.kt index 5620f005bb9..bbcdb776d54 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Collections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Collections.kt @@ -42,144 +42,6 @@ public interface MutableIterable : Iterable { override fun iterator(): MutableIterator } -public actual fun Array.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: T): Boolean = this@asList.contains(element) - override fun get(index: Int): T = this@asList[index] - override fun indexOf(element: T): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: T): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun ByteArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Byte): Boolean = this@asList.contains(element) - override fun get(index: Int): Byte = this@asList[index] - override fun indexOf(element: Byte): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Byte): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun ShortArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Short): Boolean = this@asList.contains(element) - override fun get(index: Int): Short = this@asList[index] - override fun indexOf(element: Short): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Short): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun IntArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Int): Boolean = this@asList.contains(element) - override fun get(index: Int): Int = this@asList[index] - override fun indexOf(element: Int): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Int): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun LongArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Long): Boolean = this@asList.contains(element) - override fun get(index: Int): Long = this@asList[index] - override fun indexOf(element: Long): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Long): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun FloatArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Float): Boolean = this@asList.contains(element) - override fun get(index: Int): Float = this@asList[index] - override fun indexOf(element: Float): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Float): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun DoubleArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Double): Boolean = this@asList.contains(element) - override fun get(index: Int): Double = this@asList[index] - override fun indexOf(element: Double): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Double): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun BooleanArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Boolean): Boolean = this@asList.contains(element) - override fun get(index: Int): Boolean = this@asList[index] - override fun indexOf(element: Boolean): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Boolean): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Returns a [List] that wraps the original array. - */ -public actual fun CharArray.asList(): List { - return object : AbstractList(), RandomAccess { - override val size: Int get() = this@asList.size - override fun isEmpty(): Boolean = this@asList.isEmpty() - override fun contains(element: Char): Boolean = this@asList.contains(element) - override fun get(index: Int): Char = this@asList[index] - override fun indexOf(element: Char): Int = this@asList.indexOf(element) - override fun lastIndexOf(element: Char): Int = this@asList.lastIndexOf(element) - } -} - -/** - * Reverses elements in the list in-place. - */ -public actual fun MutableList.reverse(): Unit { - val median = size / 2 - var leftIndex = 0 - var rightIndex = size - 1 - while (leftIndex < median) { - val tmp = this[leftIndex] - this[leftIndex] = this[rightIndex] - this[rightIndex] = tmp - leftIndex++ - rightIndex-- - } -} /** * Replaces each element in the list with a result of a transformation specified.