From c485511f1b97aabf8f8496535b6126f7f145435c Mon Sep 17 00:00:00 2001 From: LepilkinaElena Date: Fri, 15 May 2020 17:45:33 +0300 Subject: [PATCH] Added hack with null-check for escaping extra boxing for non-nullable keys in HashMap (#4174) --- runtime/src/main/kotlin/kotlin/collections/HashMap.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt index a8a07d23590..fdb357cb10f 100644 --- a/runtime/src/main/kotlin/kotlin/collections/HashMap.kt +++ b/runtime/src/main/kotlin/kotlin/collections/HashMap.kt @@ -190,7 +190,8 @@ actual class HashMap private constructor( return newValuesArray } - private fun hash(key: K) = (key.hashCode() * MAGIC) ushr hashShift + // Null-check for escaping extra boxing for non-nullable keys. + private fun hash(key: K) = if (key == null) 0 else (key.hashCode() * MAGIC) ushr hashShift private fun compact() { var i = 0