Make toTypedArray reified again and thus inline, rewrite copyToArray and copyToArrayImpl in kotlin.
This commit is contained in:
@@ -18,12 +18,25 @@ package kotlin.collections
|
|||||||
|
|
||||||
import kotlin.comparisons.naturalOrder
|
import kotlin.comparisons.naturalOrder
|
||||||
|
|
||||||
@library("copyToArray")
|
@Suppress("NON_PUBLIC_CALL_FROM_PUBLIC_INLINE")
|
||||||
public fun <T> Collection<T>.toTypedArray(): Array<T> = noImpl
|
public inline fun <reified T> Collection<T>.toTypedArray(): Array<T> = copyToArray(this)
|
||||||
|
|
||||||
|
@JsName("copyToArray")
|
||||||
|
internal fun <T> copyToArray(collection: Collection<T>): Array<T> {
|
||||||
|
return if (collection.asDynamic().toArray !== undefined)
|
||||||
|
collection.asDynamic().toArray()
|
||||||
|
else
|
||||||
|
copyToArrayImpl(collection).asDynamic()
|
||||||
|
}
|
||||||
|
|
||||||
@library("copyToArrayImpl")
|
@JsName("copyToArrayImpl")
|
||||||
internal fun copyToArrayImpl(collection: Collection<*>): Array<Any?> = noImpl
|
internal fun copyToArrayImpl(collection: Collection<*>): Array<Any?> {
|
||||||
|
val array = emptyArray<Any?>()
|
||||||
|
val iterator = collection.iterator()
|
||||||
|
while (iterator.hasNext())
|
||||||
|
array.asDynamic().push(iterator.next())
|
||||||
|
return array
|
||||||
|
}
|
||||||
|
|
||||||
@library("arrayToString")
|
@library("arrayToString")
|
||||||
internal fun arrayToString(array: Array<*>): String = noImpl
|
internal fun arrayToString(array: Array<*>): String = noImpl
|
||||||
|
|||||||
+1
-16
@@ -406,7 +406,7 @@ Kotlin.collectionsSort = function (mutableList, comparator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mutableList.size > 1) {
|
if (mutableList.size > 1) {
|
||||||
var array = Kotlin.copyToArray(mutableList);
|
var array = _.kotlin.collections.copyToArray(mutableList);
|
||||||
|
|
||||||
array.sort(boundComparator);
|
array.sort(boundComparator);
|
||||||
|
|
||||||
@@ -420,21 +420,6 @@ Kotlin.primitiveArraySort = function(array) {
|
|||||||
array.sort(Kotlin.primitiveCompareTo)
|
array.sort(Kotlin.primitiveCompareTo)
|
||||||
};
|
};
|
||||||
|
|
||||||
Kotlin.copyToArray = function (collection) {
|
|
||||||
if (typeof collection.toArray !== "undefined") return collection.toArray();
|
|
||||||
return Kotlin.copyToArrayImpl(collection);
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.copyToArrayImpl = function (collection) {
|
|
||||||
var array = [];
|
|
||||||
var it = collection.iterator();
|
|
||||||
while (it.hasNext()) {
|
|
||||||
array.push(it.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
return array;
|
|
||||||
};
|
|
||||||
|
|
||||||
Kotlin.splitString = function (str, regex, limit) {
|
Kotlin.splitString = function (str, regex, limit) {
|
||||||
return str.split(new RegExp(regex), limit);
|
return str.split(new RegExp(regex), limit);
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user