Use the same implementation in Array.toArrayList as in arrayListOf.

This commit is contained in:
Ilya Gorbunov
2015-10-16 19:16:29 +03:00
parent 55122cda9e
commit e24af934dc
3 changed files with 4 additions and 2 deletions
+1 -1
View File
@@ -5160,7 +5160,7 @@ public fun Array<out Short>.toShortArray(): ShortArray {
* Returns an [ArrayList] of all elements.
*/
public fun <T> Array<out T>.toArrayList(): ArrayList<T> {
return this.asList().toArrayList()
return ArrayList(this.asCollection())
}
/**
@@ -44,6 +44,8 @@ internal object EmptyList : List<Nothing>, Serializable {
private fun readResolve(): Any = EmptyList
}
internal fun <T> Array<out T>.asCollection(): Collection<T> = ArrayAsCollection(this)
private class ArrayAsCollection<T>(val values: Array<out T>): Collection<T> {
override val size: Int get() = values.size()
override fun isEmpty(): Boolean = values.isEmpty()
@@ -57,7 +57,7 @@ fun snapshots(): List<GenericFunction> {
}
body(Collections) { "return ArrayList(this)" }
body(Strings) { "return toCollection(ArrayList<T>(length()))" }
body(ArraysOfObjects) { "return this.asList().toArrayList()" }
body(ArraysOfObjects) { "return ArrayList(this.asCollection())" }
body(ArraysOfPrimitives) {
"""
val list = ArrayList<T>(size())