From dccae6c3ffbc3eb367c0df5b9508d354fe26b8d6 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Sat, 30 Jan 2016 07:21:06 +0300 Subject: [PATCH] Introduce annotation InlineExposed to indicate internal members effectively public due to usage in inlined functions. Currently, doesn't affect anything. Make collectionSizeOrDefault and collectionSizeOrNull internal, but expose them via inlining together with mapCapacity. Make Regex(Pattern) constructor exposed by inlined Pattern.toRegex --- libraries/stdlib/src/generated/_Arrays.kt | 90 +++++++++++++------ .../stdlib/src/generated/_Collections.kt | 13 ++- libraries/stdlib/src/generated/_Strings.kt | 9 +- .../stdlib/src/kotlin/collections/JUtil.kt | 7 +- .../src/kotlin/collections/MapAccessors.kt | 13 ++- .../src/kotlin/collections/MapWithDefault.kt | 1 + .../stdlib/src/kotlin/collections/Maps.kt | 7 +- .../stdlib/src/kotlin/concurrent/Timer.kt | 1 + .../stdlib/src/kotlin/internal/Annotations.kt | 7 ++ .../src/kotlin/jvm/internal/unsafe/monitor.kt | 10 +-- .../src/kotlin/text/regex/RegexExtensions.kt | 4 +- .../stdlib/src/kotlin/text/regex/RegexJVM.kt | 4 +- .../stdlib/src/kotlin/util/AssertionsJVM.kt | 2 +- .../stdlib/src/kotlin/util/Synchronized.kt | 3 +- .../src/templates/Generators.kt | 3 + .../src/templates/Mapping.kt | 6 +- .../src/templates/Snapshots.kt | 27 ++++-- 17 files changed, 145 insertions(+), 62 deletions(-) diff --git a/libraries/stdlib/src/generated/_Arrays.kt b/libraries/stdlib/src/generated/_Arrays.kt index c0a89c7ee94..49ccb28e7ae 100644 --- a/libraries/stdlib/src/generated/_Arrays.kt +++ b/libraries/stdlib/src/generated/_Arrays.kt @@ -5491,7 +5491,8 @@ public fun Array.toShortArray(): ShortArray { * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun Array.associate(transform: (T) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5501,7 +5502,8 @@ public inline fun Array.associate(transform: (T) -> Pair) * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun BooleanArray.associate(transform: (Boolean) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5511,7 +5513,8 @@ public inline fun BooleanArray.associate(transform: (Boolean) -> Pair ByteArray.associate(transform: (Byte) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5521,7 +5524,8 @@ public inline fun ByteArray.associate(transform: (Byte) -> Pair): M * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun CharArray.associate(transform: (Char) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5531,7 +5535,8 @@ public inline fun CharArray.associate(transform: (Char) -> Pair): M * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun DoubleArray.associate(transform: (Double) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5541,7 +5546,8 @@ public inline fun DoubleArray.associate(transform: (Double) -> Pair * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun FloatArray.associate(transform: (Float) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5551,7 +5557,8 @@ public inline fun FloatArray.associate(transform: (Float) -> Pair): * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun IntArray.associate(transform: (Int) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5561,7 +5568,8 @@ public inline fun IntArray.associate(transform: (Int) -> Pair): Map * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun LongArray.associate(transform: (Long) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5571,7 +5579,8 @@ public inline fun LongArray.associate(transform: (Long) -> Pair): M * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun ShortArray.associate(transform: (Short) -> Pair): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -5581,7 +5590,8 @@ public inline fun ShortArray.associate(transform: (Short) -> Pair): * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun Array.associateBy(keySelector: (T) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5591,7 +5601,8 @@ public inline fun Array.associateBy(keySelector: (T) -> K): Map BooleanArray.associateBy(keySelector: (Boolean) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5601,7 +5612,8 @@ public inline fun BooleanArray.associateBy(keySelector: (Boolean) -> K): Map * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun ByteArray.associateBy(keySelector: (Byte) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5611,7 +5623,8 @@ public inline fun ByteArray.associateBy(keySelector: (Byte) -> K): Map CharArray.associateBy(keySelector: (Char) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5621,7 +5634,8 @@ public inline fun CharArray.associateBy(keySelector: (Char) -> K): Map DoubleArray.associateBy(keySelector: (Double) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5631,7 +5645,8 @@ public inline fun DoubleArray.associateBy(keySelector: (Double) -> K): Map FloatArray.associateBy(keySelector: (Float) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5641,7 +5656,8 @@ public inline fun FloatArray.associateBy(keySelector: (Float) -> K): Map IntArray.associateBy(keySelector: (Int) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5651,7 +5667,8 @@ public inline fun IntArray.associateBy(keySelector: (Int) -> K): Map * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun LongArray.associateBy(keySelector: (Long) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5661,7 +5678,8 @@ public inline fun LongArray.associateBy(keySelector: (Long) -> K): Map ShortArray.associateBy(keySelector: (Short) -> K): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -5670,7 +5688,8 @@ public inline fun ShortArray.associateBy(keySelector: (Short) -> K): Map Array.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5679,7 +5698,8 @@ public inline fun Array.associateBy(keySelector: (T) -> K, valu * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun BooleanArray.associateBy(keySelector: (Boolean) -> K, valueTransform: (Boolean) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5688,7 +5708,8 @@ public inline fun BooleanArray.associateBy(keySelector: (Boolean) -> K, v * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun ByteArray.associateBy(keySelector: (Byte) -> K, valueTransform: (Byte) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5697,7 +5718,8 @@ public inline fun ByteArray.associateBy(keySelector: (Byte) -> K, valueTr * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun CharArray.associateBy(keySelector: (Char) -> K, valueTransform: (Char) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5706,7 +5728,8 @@ public inline fun CharArray.associateBy(keySelector: (Char) -> K, valueTr * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun DoubleArray.associateBy(keySelector: (Double) -> K, valueTransform: (Double) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5715,7 +5738,8 @@ public inline fun DoubleArray.associateBy(keySelector: (Double) -> K, val * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun FloatArray.associateBy(keySelector: (Float) -> K, valueTransform: (Float) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5724,7 +5748,8 @@ public inline fun FloatArray.associateBy(keySelector: (Float) -> K, value * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun IntArray.associateBy(keySelector: (Int) -> K, valueTransform: (Int) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5733,7 +5758,8 @@ public inline fun IntArray.associateBy(keySelector: (Int) -> K, valueTran * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun LongArray.associateBy(keySelector: (Long) -> K, valueTransform: (Long) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -5742,7 +5768,8 @@ public inline fun LongArray.associateBy(keySelector: (Long) -> K, valueTr * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun ShortArray.associateBy(keySelector: (Short) -> K, valueTransform: (Short) -> V): Map { - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -11356,6 +11383,7 @@ public infix fun ShortArray.zip(other: Iterable): List> { */ public inline fun Array.zip(other: Iterable, transform: (T, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11370,6 +11398,7 @@ public inline fun Array.zip(other: Iterable, transform: (T, */ public inline fun BooleanArray.zip(other: Iterable, transform: (Boolean, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11384,6 +11413,7 @@ public inline fun BooleanArray.zip(other: Iterable, transform: (Boolea */ public inline fun ByteArray.zip(other: Iterable, transform: (Byte, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11398,6 +11428,7 @@ public inline fun ByteArray.zip(other: Iterable, transform: (Byte, R) */ public inline fun CharArray.zip(other: Iterable, transform: (Char, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11412,6 +11443,7 @@ public inline fun CharArray.zip(other: Iterable, transform: (Char, R) */ public inline fun DoubleArray.zip(other: Iterable, transform: (Double, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11426,6 +11458,7 @@ public inline fun DoubleArray.zip(other: Iterable, transform: (Double, */ public inline fun FloatArray.zip(other: Iterable, transform: (Float, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11440,6 +11473,7 @@ public inline fun FloatArray.zip(other: Iterable, transform: (Float, R */ public inline fun IntArray.zip(other: Iterable, transform: (Int, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11454,6 +11488,7 @@ public inline fun IntArray.zip(other: Iterable, transform: (Int, R) -> */ public inline fun LongArray.zip(other: Iterable, transform: (Long, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -11468,6 +11503,7 @@ public inline fun LongArray.zip(other: Iterable, transform: (Long, R) */ public inline fun ShortArray.zip(other: Iterable, transform: (Short, R) -> V): List { val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { diff --git a/libraries/stdlib/src/generated/_Collections.kt b/libraries/stdlib/src/generated/_Collections.kt index dbb5a455a14..35743708e99 100644 --- a/libraries/stdlib/src/generated/_Collections.kt +++ b/libraries/stdlib/src/generated/_Collections.kt @@ -926,7 +926,8 @@ public fun Collection.toShortArray(): ShortArray { * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun Iterable.associate(transform: (T) -> Pair): Map { - val capacity = ((collectionSizeOrDefault(10)/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -936,7 +937,8 @@ public inline fun Iterable.associate(transform: (T) -> Pair): * If any two elements would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun Iterable.associateBy(keySelector: (T) -> K): Map { - val capacity = ((collectionSizeOrDefault(10)/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -945,7 +947,8 @@ public inline fun Iterable.associateBy(keySelector: (T) -> K): Map Iterable.associateBy(keySelector: (T) -> K, valueTransform: (T) -> V): Map { - val capacity = ((collectionSizeOrDefault(10)/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } @@ -1165,6 +1168,7 @@ public inline fun >> Iterable.gr * Returns a list containing the results of applying the given [transform] function * to each element in the original collection. */ +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") public inline fun Iterable.map(transform: (T) -> R): List { return mapTo(ArrayList(collectionSizeOrDefault(10)), transform) } @@ -1173,6 +1177,7 @@ public inline fun Iterable.map(transform: (T) -> R): List { * Returns a list containing the results of applying the given [transform] function * to each element and its index in the original collection. */ +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") public inline fun Iterable.mapIndexed(transform: (Int, T) -> R): List { return mapIndexedTo(ArrayList(collectionSizeOrDefault(10)), transform) } @@ -1805,6 +1810,7 @@ public infix fun Iterable.zip(other: Array): List> { */ public inline fun Iterable.zip(other: Array, transform: (T, R) -> V): List { val arraySize = other.size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in this) { @@ -1827,6 +1833,7 @@ public infix fun Iterable.zip(other: Iterable): List> { public inline fun Iterable.zip(other: Iterable, transform: (T, R) -> V): List { val first = iterator() val second = other.iterator() + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10))) while (first.hasNext() && second.hasNext()) { list.add(transform(first.next(), second.next())) diff --git a/libraries/stdlib/src/generated/_Strings.kt b/libraries/stdlib/src/generated/_Strings.kt index 9944a7ea2e4..b33c44907cf 100644 --- a/libraries/stdlib/src/generated/_Strings.kt +++ b/libraries/stdlib/src/generated/_Strings.kt @@ -499,7 +499,8 @@ public inline fun String.reversed(): String { * If any of two pairs would have the same key the last one gets added to the map. */ public inline fun CharSequence.associate(transform: (Char) -> Pair): Map { - val capacity = ((length/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(length).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) } @@ -509,7 +510,8 @@ public inline fun CharSequence.associate(transform: (Char) -> Pair) * If any two characters would have the same key returned by [keySelector] the last one gets added to the map. */ public inline fun CharSequence.associateBy(keySelector: (Char) -> K): Map { - val capacity = ((length/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(length).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) } @@ -518,7 +520,8 @@ public inline fun CharSequence.associateBy(keySelector: (Char) -> K): Map CharSequence.associateBy(keySelector: (Char) -> K, valueTransform: (Char) -> V): Map { - val capacity = ((length/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(length).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) } diff --git a/libraries/stdlib/src/kotlin/collections/JUtil.kt b/libraries/stdlib/src/kotlin/collections/JUtil.kt index 623ebacdbd2..a62ccd1ea1a 100644 --- a/libraries/stdlib/src/kotlin/collections/JUtil.kt +++ b/libraries/stdlib/src/kotlin/collections/JUtil.kt @@ -135,13 +135,14 @@ public inline fun Enumeration.toList(): List = Collections.list(this) /** * Returns the size of this iterable if it is known, or `null` otherwise. */ -@kotlin.internal.InlineOnly -public inline fun Iterable.collectionSizeOrNull(): Int? = if (this is Collection<*>) this.size else null +@kotlin.internal.InlineExposed +internal fun Iterable.collectionSizeOrNull(): Int? = if (this is Collection<*>) this.size else null /** * Returns the size of this iterable if it is known, or the specified [default] value otherwise. */ -public fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default +@kotlin.internal.InlineExposed +internal fun Iterable.collectionSizeOrDefault(default: Int): Int = if (this is Collection<*>) this.size else default /** Returns true when it's safe to convert this collection to a set without changing contains method behavior. */ private fun Collection.safeToConvertToSet() = size > 2 && this is ArrayList diff --git a/libraries/stdlib/src/kotlin/collections/MapAccessors.kt b/libraries/stdlib/src/kotlin/collections/MapAccessors.kt index 8e1bf5a6c79..6f759f3e753 100644 --- a/libraries/stdlib/src/kotlin/collections/MapAccessors.kt +++ b/libraries/stdlib/src/kotlin/collections/MapAccessors.kt @@ -12,7 +12,10 @@ import kotlin.internal.Exact * * @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]). */ -public operator fun Map.getValue(thisRef: Any?, property: KProperty<*>): V1 = getOrImplicitDefault(property.name) as V1 +@kotlin.internal.InlineOnly +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") +public inline operator fun Map.getValue(thisRef: Any?, property: KProperty<*>): V1 + = getOrImplicitDefault(property.name) as V1 /** * Returns the value of the property for the given object from this mutable map. @@ -23,7 +26,10 @@ public operator fun Map.getValue(thisRef: Any?, * @throws NoSuchElementException when the map doesn't contain value for the property name and doesn't provide an implicit default (see [withDefault]). */ @kotlin.jvm.JvmName("getVar") -public operator fun MutableMap.getValue(thisRef: Any?, property: KProperty<*>): V = getOrImplicitDefault(property.name) as V +@kotlin.internal.InlineOnly +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") +public inline operator fun MutableMap.getValue(thisRef: Any?, property: KProperty<*>): V + = getOrImplicitDefault(property.name) as V /** * Stores the value of the property for the given object in this mutable map. @@ -31,6 +37,7 @@ public operator fun MutableMap.getValue(thisRef: Any?, prop * @param property the metadata for the property, used to get the name of property and store the value associated with that name in the map. * @param value the value to set. */ -public operator fun MutableMap.setValue(thisRef: Any?, property: KProperty<*>, value: V) { +@kotlin.internal.InlineOnly +public inline operator fun MutableMap.setValue(thisRef: Any?, property: KProperty<*>, value: V) { this.put(property.name, value) } diff --git a/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt b/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt index 30195a66264..7de8567e3ba 100644 --- a/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt +++ b/libraries/stdlib/src/kotlin/collections/MapWithDefault.kt @@ -13,6 +13,7 @@ import java.util.* * @throws NoSuchElementException when the map doesn't contain value for the specified key and no implicit default was provided for that map. */ @kotlin.jvm.JvmName("getOrImplicitDefaultNullable") +@kotlin.internal.InlineExposed internal fun Map.getOrImplicitDefault(key: K): V { if (this is MapWithDefault) return this.getOrImplicitDefault(key) diff --git a/libraries/stdlib/src/kotlin/collections/Maps.kt b/libraries/stdlib/src/kotlin/collections/Maps.kt index dd6e3b83824..9d733df7327 100644 --- a/libraries/stdlib/src/kotlin/collections/Maps.kt +++ b/libraries/stdlib/src/kotlin/collections/Maps.kt @@ -83,6 +83,7 @@ public fun linkedMapOf(vararg pairs: Pair): LinkedHashMap private val INT_MAX_POWER_OF_TWO: Int = Int.MAX_VALUE / 2 + 1 +@kotlin.internal.InlineExposed internal fun mapCapacity(expectedSize: Int): Int { if (expectedSize < 3) { return expectedSize + 1 @@ -277,8 +278,9 @@ public fun MutableMap.putAll(pairs: Sequence>): Uni * * @sample test.collections.MapTest.mapValues */ +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") public inline fun Map.mapValues(transform: (Map.Entry) -> R): Map { - return mapValuesTo(LinkedHashMap(size), transform) + return mapValuesTo(LinkedHashMap(mapCapacity(size)), transform) } /** @@ -287,8 +289,9 @@ public inline fun Map.mapValues(transform: (Map.Entry) -> * * @sample test.collections.MapTest.mapKeys */ +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") public inline fun Map.mapKeys(transform: (Map.Entry) -> R): Map { - return mapKeysTo(LinkedHashMap(size), transform) + return mapKeysTo(LinkedHashMap(mapCapacity(size)), transform) } /** diff --git a/libraries/stdlib/src/kotlin/concurrent/Timer.kt b/libraries/stdlib/src/kotlin/concurrent/Timer.kt index 0120df8b426..77dfce26351 100644 --- a/libraries/stdlib/src/kotlin/concurrent/Timer.kt +++ b/libraries/stdlib/src/kotlin/concurrent/Timer.kt @@ -74,6 +74,7 @@ public inline fun Timer.scheduleAtFixedRate(time: Date, period: Long, crossinlin // exposed as public +@kotlin.internal.InlineExposed internal fun timer(name: String?, daemon: Boolean) = if (name == null) Timer(daemon) else Timer(name, daemon) /** diff --git a/libraries/stdlib/src/kotlin/internal/Annotations.kt b/libraries/stdlib/src/kotlin/internal/Annotations.kt index a8c0c065788..fe99cf71c42 100644 --- a/libraries/stdlib/src/kotlin/internal/Annotations.kt +++ b/libraries/stdlib/src/kotlin/internal/Annotations.kt @@ -58,3 +58,10 @@ internal annotation class OnlyInputTypes @Target(AnnotationTarget.FUNCTION) @Retention(AnnotationRetention.BINARY) internal annotation class InlineOnly + +/** + * Specifies that this part of internal API is effectively public exposed by using in public inline function + */ +@Target(AnnotationTarget.CLASS, AnnotationTarget.CONSTRUCTOR, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) +@Retention(AnnotationRetention.BINARY) +internal annotation class InlineExposed \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/jvm/internal/unsafe/monitor.kt b/libraries/stdlib/src/kotlin/jvm/internal/unsafe/monitor.kt index ea4e32aa11f..600bb5d17b7 100644 --- a/libraries/stdlib/src/kotlin/jvm/internal/unsafe/monitor.kt +++ b/libraries/stdlib/src/kotlin/jvm/internal/unsafe/monitor.kt @@ -16,10 +16,8 @@ package kotlin.jvm.internal.unsafe -/** @suppress */ -@Deprecated("This function supports the standard library infrastructure and is not intended to be used directly from user code.", level = DeprecationLevel.ERROR) -public fun monitorEnter(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately") +@kotlin.internal.InlineExposed +internal fun monitorEnter(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately") -/** @suppress */ -@Deprecated("This function supports the standard library infrastructure and is not intended to be used directly from user code.", level = DeprecationLevel.ERROR) -public fun monitorExit(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately") +@kotlin.internal.InlineExposed +internal fun monitorExit(monitor: Any): Unit = throw UnsupportedOperationException("This function can only be used privately") diff --git a/libraries/stdlib/src/kotlin/text/regex/RegexExtensions.kt b/libraries/stdlib/src/kotlin/text/regex/RegexExtensions.kt index 0e2ab1a1461..ac62bd6bdde 100644 --- a/libraries/stdlib/src/kotlin/text/regex/RegexExtensions.kt +++ b/libraries/stdlib/src/kotlin/text/regex/RegexExtensions.kt @@ -27,4 +27,6 @@ public inline fun String.toRegex(options: Set): Regex = Regex(this, * Provides the way to use Regex API on the instances of [Pattern]. */ @JvmVersion -public fun java.util.regex.Pattern.toRegex(): Regex = Regex(this) \ No newline at end of file +@kotlin.internal.InlineOnly +@Suppress("INVISIBLE_MEMBER_FROM_INLINE") +public inline fun java.util.regex.Pattern.toRegex(): Regex = Regex(this) \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt b/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt index f9f838a7b9f..e7e3c903ec2 100644 --- a/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt +++ b/libraries/stdlib/src/kotlin/text/regex/RegexJVM.kt @@ -91,7 +91,9 @@ public data class MatchGroup(public val value: String, public val range: IntRang * * For pattern syntax reference see [java.util.regex.Pattern] */ -public class Regex internal constructor(private val nativePattern: Pattern) { +public class Regex +@kotlin.internal.InlineExposed +internal constructor(private val nativePattern: Pattern) { /** Creates a regular expression from the specified [pattern] string and the default options. */ diff --git a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt index 19379779051..69258c63a6a 100644 --- a/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt +++ b/libraries/stdlib/src/kotlin/util/AssertionsJVM.kt @@ -2,7 +2,7 @@ @file:kotlin.jvm.JvmName("PreconditionsKt") package kotlin - +@kotlin.internal.InlineExposed internal object _Assertions { @JvmField internal val ENABLED: Boolean = javaClass.desiredAssertionStatus() diff --git a/libraries/stdlib/src/kotlin/util/Synchronized.kt b/libraries/stdlib/src/kotlin/util/Synchronized.kt index 989e9950528..47dec0979b1 100644 --- a/libraries/stdlib/src/kotlin/util/Synchronized.kt +++ b/libraries/stdlib/src/kotlin/util/Synchronized.kt @@ -8,14 +8,15 @@ import kotlin.jvm.internal.unsafe.* /** * Executes the given function [block] while holding the monitor of the given object [lock]. */ -@Suppress("DEPRECATION_ERROR") @kotlin.internal.InlineOnly public inline fun synchronized(lock: Any, block: () -> R): R { + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") monitorEnter(lock) try { return block() } finally { + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") monitorExit(lock) } } diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index 2cad8fde76d..54a6c538383 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -485,6 +485,7 @@ fun generators(): List { """ val first = iterator() val second = other.iterator() + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(collectionSizeOrDefault(10), other.collectionSizeOrDefault(10))) while (first.hasNext() && second.hasNext()) { list.add(transform(first.next(), second.next())) @@ -495,6 +496,7 @@ fun generators(): List { body(ArraysOfObjects, ArraysOfPrimitives) { """ val arraySize = size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(other.collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in other) { @@ -520,6 +522,7 @@ fun generators(): List { body { """ val arraySize = other.size + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") val list = ArrayList(Math.min(collectionSizeOrDefault(10), arraySize)) var i = 0 for (element in this) { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt index c051f1660d1..ab29e1dd275 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Mapping.kt @@ -34,7 +34,8 @@ fun mapping(): List { } typeParam("R") returns("List") - body { + annotations(Iterables) { """@Suppress("INVISIBLE_MEMBER_FROM_INLINE")""" } + body(Iterables) { "return mapIndexedTo(ArrayList(collectionSizeOrDefault(10)), transform)" } body(ArraysOfObjects, ArraysOfPrimitives) { @@ -61,7 +62,8 @@ fun mapping(): List { } typeParam("R") returns("List") - body { + annotations(Iterables) { """@Suppress("INVISIBLE_MEMBER_FROM_INLINE")""" } + body(Iterables) { "return mapTo(ArrayList(collectionSizeOrDefault(10)), transform)" } body(ArraysOfObjects, ArraysOfPrimitives, Maps) { diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt index 5a4592b79ed..244691a9aa6 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Snapshots.kt @@ -153,7 +153,8 @@ fun snapshots(): List { } body { """ - val capacity = ((collectionSizeOrDefault(10)/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) """ } @@ -164,13 +165,15 @@ fun snapshots(): List { } body(CharSequences) { """ - val capacity = ((length/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(length).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) """ } body(ArraysOfObjects, ArraysOfPrimitives) { """ - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateTo(LinkedHashMap(capacity), transform) """ } @@ -228,7 +231,8 @@ fun snapshots(): List { body { """ - val capacity = ((collectionSizeOrDefault(10)/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) """ } @@ -239,13 +243,15 @@ fun snapshots(): List { } body(CharSequences) { """ - val capacity = ((length/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(length).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) """ } body(ArraysOfObjects, ArraysOfPrimitives) { """ - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector) """ } @@ -319,7 +325,8 @@ fun snapshots(): List { body { """ - val capacity = ((collectionSizeOrDefault(10)/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(collectionSizeOrDefault(10)).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) """ } @@ -330,13 +337,15 @@ fun snapshots(): List { } body(CharSequences) { """ - val capacity = ((length/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(length).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) """ } body(ArraysOfObjects, ArraysOfPrimitives) { """ - val capacity = ((size/.75f) + 1).toInt().coerceAtLeast(16) + @Suppress("INVISIBLE_MEMBER_FROM_INLINE") + val capacity = mapCapacity(size).coerceAtLeast(16) return associateByTo(LinkedHashMap(capacity), keySelector, valueTransform) """ }