KT-15363 Fix failing test: missing capacity parameter check in JS
Partially restore JVM map capacity implementation
This commit is contained in:
@@ -178,6 +178,7 @@ public inline fun <E> buildList(@BuilderInference builderAction: MutableList<E>.
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <E> buildList(expectedSize: Int, @BuilderInference builderAction: MutableList<E>.() -> Unit): List<E> {
|
||||
contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
|
||||
checkBuilderCapacity(expectedSize)
|
||||
return ArrayList<E>(expectedSize).apply(builderAction)
|
||||
}
|
||||
|
||||
|
||||
@@ -148,6 +148,7 @@ public inline fun <K, V> buildMap(@BuilderInference builderAction: MutableMap<K,
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <K, V> buildMap(expectedSize: Int, @BuilderInference builderAction: MutableMap<K, V>.() -> Unit): Map<K, V> {
|
||||
contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
|
||||
checkBuilderCapacity(expectedSize)
|
||||
return LinkedHashMap<K, V>(mapCapacity(expectedSize)).apply(builderAction)
|
||||
}
|
||||
|
||||
@@ -157,6 +158,14 @@ public inline fun <K, V> buildMap(expectedSize: Int, @BuilderInference builderAc
|
||||
@PublishedApi
|
||||
internal expect fun mapCapacity(expectedSize: Int): Int
|
||||
|
||||
/**
|
||||
* Checks a collection builder function capacity argument.
|
||||
*/
|
||||
@SinceKotlin("1.3")
|
||||
@ExperimentalStdlibApi
|
||||
@PublishedApi
|
||||
internal expect fun checkBuilderCapacity(capacity: Int)
|
||||
|
||||
/** Returns `true` if this map is not empty. */
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <K, V> Map<out K, V>.isNotEmpty(): Boolean = !isEmpty()
|
||||
|
||||
@@ -115,6 +115,7 @@ public inline fun <E> buildSet(@BuilderInference builderAction: MutableSet<E>.()
|
||||
@kotlin.internal.InlineOnly
|
||||
public inline fun <E> buildSet(expectedSize: Int, @BuilderInference builderAction: MutableSet<E>.() -> Unit): Set<E> {
|
||||
contract { callsInPlace(builderAction, InvocationKind.EXACTLY_ONCE) }
|
||||
checkBuilderCapacity(expectedSize)
|
||||
return LinkedHashSet<E>(mapCapacity(expectedSize)).apply(builderAction)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user