Collection builders: specialize internal capacity helpers

(cherry picked from commit 4c26535cebaa847249e942c1d983d50fd94f2f39)
This commit is contained in:
Ilya Gorbunov
2020-01-24 06:13:36 +03:00
committed by Vasily Levchenko
parent b711f14ae9
commit e4190d4ae8
@@ -12,3 +12,21 @@ internal inline actual fun <K, V> Map<K, V>.toSingletonMapOrSelf(): Map<K, V> =
// creates a singleton copy of map
internal actual fun <K, V> Map<out K, V>.toSingletonMap(): Map<K, V>
= with(entries.iterator().next()) { mutableMapOf(key to value) }
/**
* Native map and set implementations do not make use of capacities or load factors.
*/
@PublishedApi
internal actual fun mapCapacity(expectedSize: Int) = expectedSize
/**
* Checks a collection builder function capacity argument.
* Does nothing, capacity is validated in List/Set/Map constructor
*/
@SinceKotlin("1.3")
@ExperimentalStdlibApi
@PublishedApi
internal actual fun checkBuilderCapacity(capacity: Int) {
require(capacity >= 0) { "capacity must be non-negative." }
}