From ad25d3ca7c0be508e704104b5df2ed21d90ccadd Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Thu, 13 Apr 2017 17:15:45 +0700 Subject: [PATCH] stdlib: Return a RandomAccess object from Array.toList() and emptyList() --- runtime/src/main/kotlin/kotlin/collections/Collections.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/collections/Collections.kt b/runtime/src/main/kotlin/kotlin/collections/Collections.kt index 137098677d4..2ec2349366f 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Collections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Collections.kt @@ -27,7 +27,7 @@ internal object EmptyIterator : ListIterator { override fun previous(): Nothing = throw NoSuchElementException() } -internal object EmptyList : List/*, RandomAccess */ { +internal object EmptyList : List, RandomAccess { override fun equals(other: Any?): Boolean = other is List<*> && other.isEmpty() override fun hashCode(): Int = 1 @@ -187,7 +187,7 @@ public interface MutableIterable : Iterable { } public fun Array.asList(): List { - return object : AbstractList() { + return object : AbstractList(), RandomAccess { override val size: Int get() = this@asList.size override fun isEmpty(): Boolean = this@asList.isEmpty() override fun contains(element: T): Boolean = this@asList.contains(element)