@@ -8686,7 +8686,7 @@ public inline fun <K, V, M : MutableMap<in K, in V>> CharArray.associateTo(desti
8686
8686
@SinceKotlin("1.4")
8687
8687
@ExperimentalStdlibApi
8688
8688
public inline fun <K, V> Array<out K>.associateWith(valueSelector: (K) -> V): Map<K, V> {
8689
- val result = LinkedHashMap<K, V>()
8689
+ val result = LinkedHashMap<K, V>(mapCapacity(size).coerceAtLeast(16) )
8690
8690
return associateWithTo(result, valueSelector)
8691
8691
}
8692
8692
@@ -8704,7 +8704,7 @@ public inline fun <K, V> Array<out K>.associateWith(valueSelector: (K) -> V): Ma
8704
8704
@ExperimentalStdlibApi
8705
8705
@kotlin.internal.InlineOnly
8706
8706
public inline fun <V> ByteArray.associateWith(valueSelector: (Byte) -> V): Map<Byte, V> {
8707
- val result = LinkedHashMap<Byte, V>()
8707
+ val result = LinkedHashMap<Byte, V>(mapCapacity(size).coerceAtLeast(16) )
8708
8708
return associateWithTo(result, valueSelector)
8709
8709
}
8710
8710
@@ -8722,7 +8722,7 @@ public inline fun <V> ByteArray.associateWith(valueSelector: (Byte) -> V): Map<B
8722
8722
@ExperimentalStdlibApi
8723
8723
@kotlin.internal.InlineOnly
8724
8724
public inline fun <V> ShortArray.associateWith(valueSelector: (Short) -> V): Map<Short, V> {
8725
- val result = LinkedHashMap<Short, V>()
8725
+ val result = LinkedHashMap<Short, V>(mapCapacity(size).coerceAtLeast(16) )
8726
8726
return associateWithTo(result, valueSelector)
8727
8727
}
8728
8728
@@ -8740,7 +8740,7 @@ public inline fun <V> ShortArray.associateWith(valueSelector: (Short) -> V): Map
8740
8740
@ExperimentalStdlibApi
8741
8741
@kotlin.internal.InlineOnly
8742
8742
public inline fun <V> IntArray.associateWith(valueSelector: (Int) -> V): Map<Int, V> {
8743
- val result = LinkedHashMap<Int, V>()
8743
+ val result = LinkedHashMap<Int, V>(mapCapacity(size).coerceAtLeast(16) )
8744
8744
return associateWithTo(result, valueSelector)
8745
8745
}
8746
8746
@@ -8758,7 +8758,7 @@ public inline fun <V> IntArray.associateWith(valueSelector: (Int) -> V): Map<Int
8758
8758
@ExperimentalStdlibApi
8759
8759
@kotlin.internal.InlineOnly
8760
8760
public inline fun <V> LongArray.associateWith(valueSelector: (Long) -> V): Map<Long, V> {
8761
- val result = LinkedHashMap<Long, V>()
8761
+ val result = LinkedHashMap<Long, V>(mapCapacity(size).coerceAtLeast(16) )
8762
8762
return associateWithTo(result, valueSelector)
8763
8763
}
8764
8764
@@ -8776,7 +8776,7 @@ public inline fun <V> LongArray.associateWith(valueSelector: (Long) -> V): Map<L
8776
8776
@ExperimentalStdlibApi
8777
8777
@kotlin.internal.InlineOnly
8778
8778
public inline fun <V> FloatArray.associateWith(valueSelector: (Float) -> V): Map<Float, V> {
8779
- val result = LinkedHashMap<Float, V>()
8779
+ val result = LinkedHashMap<Float, V>(mapCapacity(size).coerceAtLeast(16) )
8780
8780
return associateWithTo(result, valueSelector)
8781
8781
}
8782
8782
@@ -8794,7 +8794,7 @@ public inline fun <V> FloatArray.associateWith(valueSelector: (Float) -> V): Map
8794
8794
@ExperimentalStdlibApi
8795
8795
@kotlin.internal.InlineOnly
8796
8796
public inline fun <V> DoubleArray.associateWith(valueSelector: (Double) -> V): Map<Double, V> {
8797
- val result = LinkedHashMap<Double, V>()
8797
+ val result = LinkedHashMap<Double, V>(mapCapacity(size).coerceAtLeast(16) )
8798
8798
return associateWithTo(result, valueSelector)
8799
8799
}
8800
8800
@@ -8812,7 +8812,7 @@ public inline fun <V> DoubleArray.associateWith(valueSelector: (Double) -> V): M
8812
8812
@ExperimentalStdlibApi
8813
8813
@kotlin.internal.InlineOnly
8814
8814
public inline fun <V> BooleanArray.associateWith(valueSelector: (Boolean) -> V): Map<Boolean, V> {
8815
- val result = LinkedHashMap<Boolean, V>()
8815
+ val result = LinkedHashMap<Boolean, V>(mapCapacity(size).coerceAtLeast(16) )
8816
8816
return associateWithTo(result, valueSelector)
8817
8817
}
8818
8818
@@ -8830,7 +8830,7 @@ public inline fun <V> BooleanArray.associateWith(valueSelector: (Boolean) -> V):
8830
8830
@ExperimentalStdlibApi
8831
8831
@kotlin.internal.InlineOnly
8832
8832
public inline fun <V> CharArray.associateWith(valueSelector: (Char) -> V): Map<Char, V> {
8833
- val result = LinkedHashMap<Char, V>()
8833
+ val result = LinkedHashMap<Char, V>(mapCapacity(size.coerceAtMost(128)).coerceAtLeast(16) )
8834
8834
return associateWithTo(result, valueSelector)
8835
8835
}
8836
8836
@@ -9145,7 +9145,7 @@ public fun BooleanArray.toHashSet(): HashSet<Boolean> {
9145
9145
* Returns a new [HashSet] of all elements.
9146
9146
*/
9147
9147
public fun CharArray.toHashSet(): HashSet<Char> {
9148
- return toCollection(HashSet<Char>(mapCapacity(size)))
9148
+ return toCollection(HashSet<Char>(mapCapacity(size.coerceAtMost(128) )))
9149
9149
}
9150
9150
9151
9151
/**
@@ -9439,7 +9439,7 @@ public fun CharArray.toSet(): Set<Char> {
9439
9439
return when (size) {
9440
9440
0 -> emptySet()
9441
9441
1 -> setOf(this[0])
9442
- else -> toCollection(LinkedHashSet<Char>(mapCapacity(size)))
9442
+ else -> toCollection(LinkedHashSet<Char>(mapCapacity(size.coerceAtMost(128) )))
9443
9443
}
9444
9444
}
9445
9445
@@ -11168,9 +11168,7 @@ public infix fun CharArray.subtract(other: Iterable<Char>): Set<Char> {
11168
11168
* The returned set preserves the element iteration order of the original array.
11169
11169
*/
11170
11170
public fun <T> Array<out T>.toMutableSet(): MutableSet<T> {
11171
- val set = LinkedHashSet<T>(mapCapacity(size))
11172
- for (item in this) set.add(item)
11173
- return set
11171
+ return toCollection(LinkedHashSet<T>(mapCapacity(size)))
11174
11172
}
11175
11173
11176
11174
/**
@@ -11179,9 +11177,7 @@ public fun <T> Array<out T>.toMutableSet(): MutableSet<T> {
11179
11177
* The returned set preserves the element iteration order of the original array.
11180
11178
*/
11181
11179
public fun ByteArray.toMutableSet(): MutableSet<Byte> {
11182
- val set = LinkedHashSet<Byte>(mapCapacity(size))
11183
- for (item in this) set.add(item)
11184
- return set
11180
+ return toCollection(LinkedHashSet<Byte>(mapCapacity(size)))
11185
11181
}
11186
11182
11187
11183
/**
@@ -11190,9 +11186,7 @@ public fun ByteArray.toMutableSet(): MutableSet<Byte> {
11190
11186
* The returned set preserves the element iteration order of the original array.
11191
11187
*/
11192
11188
public fun ShortArray.toMutableSet(): MutableSet<Short> {
11193
- val set = LinkedHashSet<Short>(mapCapacity(size))
11194
- for (item in this) set.add(item)
11195
- return set
11189
+ return toCollection(LinkedHashSet<Short>(mapCapacity(size)))
11196
11190
}
11197
11191
11198
11192
/**
@@ -11201,9 +11195,7 @@ public fun ShortArray.toMutableSet(): MutableSet<Short> {
11201
11195
* The returned set preserves the element iteration order of the original array.
11202
11196
*/
11203
11197
public fun IntArray.toMutableSet(): MutableSet<Int> {
11204
- val set = LinkedHashSet<Int>(mapCapacity(size))
11205
- for (item in this) set.add(item)
11206
- return set
11198
+ return toCollection(LinkedHashSet<Int>(mapCapacity(size)))
11207
11199
}
11208
11200
11209
11201
/**
@@ -11212,9 +11204,7 @@ public fun IntArray.toMutableSet(): MutableSet<Int> {
11212
11204
* The returned set preserves the element iteration order of the original array.
11213
11205
*/
11214
11206
public fun LongArray.toMutableSet(): MutableSet<Long> {
11215
- val set = LinkedHashSet<Long>(mapCapacity(size))
11216
- for (item in this) set.add(item)
11217
- return set
11207
+ return toCollection(LinkedHashSet<Long>(mapCapacity(size)))
11218
11208
}
11219
11209
11220
11210
/**
@@ -11223,9 +11213,7 @@ public fun LongArray.toMutableSet(): MutableSet<Long> {
11223
11213
* The returned set preserves the element iteration order of the original array.
11224
11214
*/
11225
11215
public fun FloatArray.toMutableSet(): MutableSet<Float> {
11226
- val set = LinkedHashSet<Float>(mapCapacity(size))
11227
- for (item in this) set.add(item)
11228
- return set
11216
+ return toCollection(LinkedHashSet<Float>(mapCapacity(size)))
11229
11217
}
11230
11218
11231
11219
/**
@@ -11234,9 +11222,7 @@ public fun FloatArray.toMutableSet(): MutableSet<Float> {
11234
11222
* The returned set preserves the element iteration order of the original array.
11235
11223
*/
11236
11224
public fun DoubleArray.toMutableSet(): MutableSet<Double> {
11237
- val set = LinkedHashSet<Double>(mapCapacity(size))
11238
- for (item in this) set.add(item)
11239
- return set
11225
+ return toCollection(LinkedHashSet<Double>(mapCapacity(size)))
11240
11226
}
11241
11227
11242
11228
/**
@@ -11245,9 +11231,7 @@ public fun DoubleArray.toMutableSet(): MutableSet<Double> {
11245
11231
* The returned set preserves the element iteration order of the original array.
11246
11232
*/
11247
11233
public fun BooleanArray.toMutableSet(): MutableSet<Boolean> {
11248
- val set = LinkedHashSet<Boolean>(mapCapacity(size))
11249
- for (item in this) set.add(item)
11250
- return set
11234
+ return toCollection(LinkedHashSet<Boolean>(mapCapacity(size)))
11251
11235
}
11252
11236
11253
11237
/**
@@ -11256,9 +11240,7 @@ public fun BooleanArray.toMutableSet(): MutableSet<Boolean> {
11256
11240
* The returned set preserves the element iteration order of the original array.
11257
11241
*/
11258
11242
public fun CharArray.toMutableSet(): MutableSet<Char> {
11259
- val set = LinkedHashSet<Char>(mapCapacity(size))
11260
- for (item in this) set.add(item)
11261
- return set
11243
+ return toCollection(LinkedHashSet<Char>(mapCapacity(size.coerceAtMost(128))))
11262
11244
}
11263
11245
11264
11246
/**
0 commit comments