diff --git a/libraries/stdlib/js/src/kotlin/collections/HashMap.kt b/libraries/stdlib/js/src/kotlin/collections/HashMap.kt index c0e48f98441..a03890507cd 100644 --- a/libraries/stdlib/js/src/kotlin/collections/HashMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/HashMap.kt @@ -48,11 +48,7 @@ public actual open class HashMap : AbstractMutableMap, MutableMap= 0) { "Negative initial capacity: $initialCapacity" } - require(loadFactor > 0) { "Non-positive load factor: $loadFactor" } - } + actual constructor(initialCapacity: Int, loadFactor: Float) : this(InternalHashMap(initialCapacity, loadFactor)) /** * Creates a new empty [HashMap] with the specified initial capacity. @@ -71,13 +67,10 @@ public actual open class HashMap : AbstractMutableMap, MutableMap) : this() { - this.putAll(original) - } + actual constructor(original: Map) : this(InternalHashMap(original)) actual override fun clear() { internalMap.clear() -// structureChanged(this) } actual override fun containsKey(key: K): Boolean = internalMap.contains(key) diff --git a/libraries/stdlib/js/src/kotlin/collections/InternalHashMap.kt b/libraries/stdlib/js/src/kotlin/collections/InternalHashMap.kt index 57e209c45f6..ab6a3cb7a4b 100644 --- a/libraries/stdlib/js/src/kotlin/collections/InternalHashMap.kt +++ b/libraries/stdlib/js/src/kotlin/collections/InternalHashMap.kt @@ -80,7 +80,6 @@ internal class InternalHashMap private constructor( } fun isEmpty(): Boolean = _size == 0 - fun containsKey(key: K): Boolean = findKey(key) >= 0 override fun containsValue(value: V): Boolean = findValue(value) >= 0 override operator fun get(key: K): V? { @@ -90,11 +89,10 @@ internal class InternalHashMap private constructor( } override fun contains(key: K): Boolean { - return containsKey(key) + return findKey(key) >= 0 } override fun put(key: K, value: V): V? { - checkIsMutable() val index = addKey(key) val valuesArray = allocateValuesArray() if (index < 0) { @@ -286,7 +284,7 @@ internal class InternalHashMap private constructor( return TOMBSTONE } - internal fun addKey(key: K): Int { + private fun addKey(key: K): Int { checkIsMutable() retry@ while (true) { var hash = hash(key) @@ -320,7 +318,7 @@ internal class InternalHashMap private constructor( } } - internal fun removeKey(key: K): Int { + private fun removeKey(key: K): Int { checkIsMutable() val index = findKey(key) if (index < 0) return TOMBSTONE @@ -405,15 +403,6 @@ internal class InternalHashMap private constructor( } } - internal fun getKey(key: K): K? { - val index = findKey(key) - return if (index >= 0) { - keysArray[index]!! - } else { - null - } - } - private fun contentEquals(other: Map<*, *>): Boolean = _size == other.size && containsAllEntries(other.entries) private fun putEntry(entry: Map.Entry): Boolean {