From 11314a5c4e057a463944e10e67a7a7d5078f1f32 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 1 Sep 2021 18:21:14 +0300 Subject: [PATCH] Rename enabling old behavior property and make it cached in a field Mention the property name in the note about conversion to set. #KT-45438 --- .../stdlib/common/src/generated/_Collections.kt | 15 +++++++++------ .../stdlib/common/src/generated/_Sequences.kt | 15 +++++++++------ libraries/stdlib/common/src/generated/_Sets.kt | 15 +++++++++------ .../jvm/src/kotlin/collections/CollectionsJVM.kt | 11 +++++++++-- .../kotlin-stdlib-gen/src/templates/Generators.kt | 5 +++-- 5 files changed, 39 insertions(+), 22 deletions(-) diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index f32e2a68271..d3aeab11503 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -2990,8 +2990,9 @@ public operator fun Iterable.minus(element: T): List { /** * Returns a list containing all elements of the original collection except the elements contained in the given [elements] array. * - * The [elements] array may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] array may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Iterable.minus(elements: Array): List { if (elements.isEmpty()) return this.toList() @@ -3002,8 +3003,9 @@ public operator fun Iterable.minus(elements: Array): List { /** * Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection. * - * The [elements] collection may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] collection may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Iterable.minus(elements: Iterable): List { val other = elements.convertToSetForSetOperationWith(this) @@ -3015,8 +3017,9 @@ public operator fun Iterable.minus(elements: Iterable): List { /** * Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence. * - * The [elements] sequence may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] sequence may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Iterable.minus(elements: Sequence): List { val other = elements.convertToSetForSetOperation() diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index 666ba223655..be96900b210 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -2440,8 +2440,9 @@ public operator fun Sequence.minus(element: T): Sequence { * Note that the source sequence and the array being subtracted are iterated only when an `iterator` is requested from * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. * - * The [elements] array may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] array may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. * * The operation is _intermediate_ and _stateful_. */ @@ -2461,8 +2462,9 @@ public operator fun Sequence.minus(elements: Array): Sequence { * Note that the source sequence and the collection being subtracted are iterated only when an `iterator` is requested from * the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result. * - * The [elements] collection may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] collection may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. * * The operation is _intermediate_ and _stateful_. */ @@ -2486,8 +2488,9 @@ public operator fun Sequence.minus(elements: Iterable): Sequence { * * The operation is _intermediate_ for this sequence and _terminal_ and _stateful_ for the [elements] sequence. * - * The [elements] sequence may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] sequence may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Sequence.minus(elements: Sequence): Sequence { return object: Sequence { diff --git a/libraries/stdlib/common/src/generated/_Sets.kt b/libraries/stdlib/common/src/generated/_Sets.kt index 0599935c164..f1761d17a4e 100644 --- a/libraries/stdlib/common/src/generated/_Sets.kt +++ b/libraries/stdlib/common/src/generated/_Sets.kt @@ -33,8 +33,9 @@ public operator fun Set.minus(element: T): Set { * * The returned set preserves the element iteration order of the original set. * - * The [elements] array may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] array may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Set.minus(elements: Array): Set { val result = LinkedHashSet(this) @@ -47,8 +48,9 @@ public operator fun Set.minus(elements: Array): Set { * * The returned set preserves the element iteration order of the original set. * - * The [elements] collection may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] collection may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Set.minus(elements: Iterable): Set { val other = elements.convertToSetForSetOperationWith(this) @@ -66,8 +68,9 @@ public operator fun Set.minus(elements: Iterable): Set { * * The returned set preserves the element iteration order of the original set. * - * The [elements] sequence may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - * a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + * Before Kotlin 1.6, the [elements] sequence may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + * a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + * On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. */ public operator fun Set.minus(elements: Sequence): Set { val result = LinkedHashSet(this) diff --git a/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt b/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt index 899d37fca2e..d229c8d25a2 100644 --- a/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt +++ b/libraries/stdlib/jvm/src/kotlin/collections/CollectionsJVM.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -124,4 +124,11 @@ internal actual inline fun checkCountOverflow(count: Int): Int { } -internal actual fun brittleContainsOptimizationEnabled(): Boolean = System.getProperty("kotlin.collections.removing.legacymode").toBoolean() +@Suppress("NOTHING_TO_INLINE") +internal actual inline fun brittleContainsOptimizationEnabled(): Boolean = CollectionSystemProperties.brittleContainsOptimizationEnabled + +internal object CollectionSystemProperties { + @JvmField + internal val brittleContainsOptimizationEnabled: Boolean = + System.getProperty("kotlin.collections.convert_arg_to_set_in_removeAll")?.toBoolean() ?: false +} \ No newline at end of file diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index 75dcda2ff5a..8c5662c4d57 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -369,8 +369,9 @@ object Generators : TemplateGroupBase() { private fun elementsConversionClause(elements: Family) = """ - The [elements] ${elements.doc.collection} may be converted to a [HashSet] to speed up the operation, thus the elements are required to have - a correct and stable implementation of `hashCode()` that doesn't change between successive invocations. + Before Kotlin 1.6, the [elements] ${elements.doc.collection} may have been converted to a [HashSet] to speed up the operation, thus the elements were required to have + a correct and stable implementation of `hashCode()` that didn't change between successive invocations. + On JVM, you can enable this behavior back with the system property `kotlin.collections.convert_arg_to_set_in_removeAll` set to `true`. """ val f_minus_iterable = fn("minus(elements: Iterable)") {