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:
committed by
Space Team
parent
60455daa9d
commit
6fdfd4e8dd
@@ -54,12 +54,11 @@ internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<
|
||||
while (iterator.hasNext()) {
|
||||
array[index++] = iterator.next().unsafeCast<T>()
|
||||
}
|
||||
if (index < array.size) {
|
||||
array[index] = null.unsafeCast<T>()
|
||||
}
|
||||
return array
|
||||
return terminateCollectionToArray(collection.size, array)
|
||||
}
|
||||
|
||||
internal actual fun <T> terminateCollectionToArray(collectionSize: Int, array: Array<T>): Array<T> = array
|
||||
|
||||
/**
|
||||
* Returns a new read-only list containing only the specified object [element].
|
||||
*
|
||||
|
||||
@@ -171,11 +171,7 @@ public actual open class ArrayList<E> internal constructor(private var array: Ar
|
||||
|
||||
(this.array as Array<T>).copyInto(array)
|
||||
|
||||
if (array.size > size) {
|
||||
array[size] = null as T // null-terminate
|
||||
}
|
||||
|
||||
return array
|
||||
return terminateCollectionToArray(size, array)
|
||||
}
|
||||
|
||||
override fun toArray(): Array<Any?> {
|
||||
|
||||
Reference in New Issue
Block a user