From be646930cc79d449c75127ff34ecae0fb4999315 Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Fri, 21 Apr 2017 16:02:11 +0300 Subject: [PATCH] Prevent init order issues in maps (#517) --- runtime/src/main/kotlin/kotlin/collections/Maps.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/collections/Maps.kt b/runtime/src/main/kotlin/kotlin/collections/Maps.kt index 7ea7221bdce..8f114e2eda3 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Maps.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Maps.kt @@ -110,13 +110,14 @@ internal fun mapCapacity(expectedSize: Int): Int { if (expectedSize < 3) { return expectedSize + 1 } - if (expectedSize < INT_MAX_POWER_OF_TWO) { + if (expectedSize < 0x40000000 /* INT_MAX_POWER_OF_TWO */) { return expectedSize + expectedSize / 3 } - return Int.MAX_VALUE // any large value + return 0x7fffffff // any large value } -private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 +// Using global constant with dependency like that introduces weird init order dependencies. +// private const val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 /** Returns `true` if this map is not empty. */ @kotlin.internal.InlineOnly