Optimize the implementation of emptyList, emptySet and emptyMap and make them serializable.

Specialized implementations of singleton List, Set and Map are used in JVM.

#KT-6682 Fixed
#KT-7104 Fixed
#KT-4840 Fixed
This commit is contained in:
Ilya Gorbunov
2015-05-14 21:25:43 +03:00
parent b7277cd80c
commit edc471c8ec
6 changed files with 143 additions and 61 deletions
+17
View File
@@ -33,3 +33,20 @@ public fun booleanArrayOf(vararg content : Boolean): BooleanArray = noImpl
library("copyToArray")
public fun <reified T> Collection<T>.toTypedArray(): Array<T> = noImpl
/**
* Returns an immutable list containing only the specified object [value].
*/
public fun listOf<T>(value: T): List<T> = arrayListOf(value)
/**
* Returns an immutable set containing only the specified object [value].
*/
public fun setOf<T>(value: T): Set<T> = hashSetOf(value)
/**
* Returns an immutable map, mapping only the specified key to the
* specified value.
*/
public fun mapOf<K, V>(keyValuePair: Pair<K, V>): Map<K, V> = hashMapOf(keyValuePair)