Null-terminate Collection.toArray destination only in JVM

In other platforms the elements following the collection elements
should not be changed.

As a part of efforts to stabilize Native stdlib.
This commit is contained in:
Abduqodiri Qurbonzoda
2023-06-01 12:52:46 +03:00
committed by Space Team
parent 60455daa9d
commit 6fdfd4e8dd
14 changed files with 46 additions and 40 deletions
@@ -221,11 +221,7 @@ actual class ArrayList<E> private constructor(
(backingArray as Array<T>).copyInto(array, 0, startIndex = offset, endIndex = offset + length)
if (array.size > length) {
array[length] = null as T // null-terminate
}
return array
return terminateCollectionToArray(length, array)
}
override fun toArray(): Array<Any?> {
@@ -93,6 +93,8 @@ internal actual fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
return array
}
internal actual fun <T> terminateCollectionToArray(collectionSize: Int, array: Array<T>): Array<T> = array
/**
* Returns a new array which is a copy of the original array with new elements filled with null values.
*/