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
This commit is contained in:
Ilya Gorbunov
2021-09-01 18:21:14 +03:00
parent 94b371af5b
commit 11314a5c4e
5 changed files with 39 additions and 22 deletions
@@ -2990,8 +2990,9 @@ public operator fun <T> Iterable<T>.minus(element: T): List<T> {
/**
* 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 <T> Iterable<T>.minus(elements: Array<out T>): List<T> {
if (elements.isEmpty()) return this.toList()
@@ -3002,8 +3003,9 @@ public operator fun <T> Iterable<T>.minus(elements: Array<out T>): List<T> {
/**
* 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 <T> Iterable<T>.minus(elements: Iterable<T>): List<T> {
val other = elements.convertToSetForSetOperationWith(this)
@@ -3015,8 +3017,9 @@ public operator fun <T> Iterable<T>.minus(elements: Iterable<T>): List<T> {
/**
* 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 <T> Iterable<T>.minus(elements: Sequence<T>): List<T> {
val other = elements.convertToSetForSetOperation()
@@ -2440,8 +2440,9 @@ public operator fun <T> Sequence<T>.minus(element: T): Sequence<T> {
* 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 <T> Sequence<T>.minus(elements: Array<out T>): Sequence<T> {
* 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 <T> Sequence<T>.minus(elements: Iterable<T>): Sequence<T> {
*
* 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 <T> Sequence<T>.minus(elements: Sequence<T>): Sequence<T> {
return object: Sequence<T> {
@@ -33,8 +33,9 @@ public operator fun <T> Set<T>.minus(element: T): Set<T> {
*
* 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 <T> Set<T>.minus(elements: Array<out T>): Set<T> {
val result = LinkedHashSet<T>(this)
@@ -47,8 +48,9 @@ public operator fun <T> Set<T>.minus(elements: Array<out T>): Set<T> {
*
* 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 <T> Set<T>.minus(elements: Iterable<T>): Set<T> {
val other = elements.convertToSetForSetOperationWith(this)
@@ -66,8 +68,9 @@ public operator fun <T> Set<T>.minus(elements: Iterable<T>): Set<T> {
*
* 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 <T> Set<T>.minus(elements: Sequence<T>): Set<T> {
val result = LinkedHashSet<T>(this)
@@ -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
}
@@ -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<T>)") {