[WASM] Workaround about call toTypedArray on AbstractCollection
This commit is contained in:
@@ -93,37 +93,6 @@ internal actual fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
|
||||
return array
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
internal actual fun <T> copyToArrayImpl(collection: Collection<*>, array: Array<T>): Array<T> {
|
||||
if (array.size < collection.size)
|
||||
return copyToArrayImpl(collection) as Array<T>
|
||||
|
||||
val iterator = collection.iterator()
|
||||
var index = 0
|
||||
while (iterator.hasNext()) {
|
||||
array[index++] = iterator.next() as T
|
||||
}
|
||||
if (index < array.size) {
|
||||
return array.copyOf(index) as Array<T>
|
||||
}
|
||||
return array
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a *typed* array containing all of the elements of this collection.
|
||||
*
|
||||
* Allocates an array of runtime type `T` having its size equal to the size of this collection
|
||||
* and populates the array with the elements of this collection.
|
||||
* @sample samples.collections.Collections.Collections.collectionToTypedArray
|
||||
*/
|
||||
public actual inline fun <reified T> Collection<T>.toTypedArray(): Array<T> {
|
||||
val result = arrayOfNulls<T>(size)
|
||||
var index = 0
|
||||
for (element in this) result[index++] = element
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return result as Array<T>
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a new array which is a copy of the original array with new elements filled with null values.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user