From e4190d4ae83bbdf557e476aee89c363a2ce680e7 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Fri, 24 Jan 2020 06:13:36 +0300 Subject: [PATCH] Collection builders: specialize internal capacity helpers (cherry picked from commit 4c26535cebaa847249e942c1d983d50fd94f2f39) --- .../src/main/kotlin/kotlin/collections/Maps.kt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/runtime/src/main/kotlin/kotlin/collections/Maps.kt b/runtime/src/main/kotlin/kotlin/collections/Maps.kt index 8d7203e48c6..e511d99317c 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Maps.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Maps.kt @@ -12,3 +12,21 @@ internal inline actual fun Map.toSingletonMapOrSelf(): Map = // creates a singleton copy of map internal actual fun Map.toSingletonMap(): Map = 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." } +} \ No newline at end of file