Remove the brittle contains optimization code #KT-47707

This commit is contained in:
Abduqodiri Qurbonzoda
2022-09-07 02:01:09 +03:00
committed by Space
parent 51fd2af6fd
commit 7060811c8b
9 changed files with 30 additions and 161 deletions
@@ -3141,26 +3141,17 @@ 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.
*
* 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()
val other = elements.convertToSetForSetOperation()
return this.filterNot { it in other }
return this.filterNot { it in elements }
}
/**
* Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection.
*
* 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)
val other = elements.convertToListIfNotCollection()
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
@@ -3168,13 +3159,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.
*
* 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()
val other = elements.toList()
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
@@ -2610,10 +2610,6 @@ 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.
*
* 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_.
*/
@@ -2621,8 +2617,7 @@ public operator fun <T> Sequence<T>.minus(elements: Array<out T>): Sequence<T> {
if (elements.isEmpty()) return this
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = elements.convertToSetForSetOperation()
return this@minus.filterNot { it in other }.iterator()
return this@minus.filterNot { it in elements }.iterator()
}
}
}
@@ -2632,17 +2627,13 @@ 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.
*
* 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_.
*/
public operator fun <T> Sequence<T>.minus(elements: Iterable<T>): Sequence<T> {
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = elements.convertToSetForSetOperation()
val other = elements.convertToListIfNotCollection()
if (other.isEmpty())
return this@minus.iterator()
else
@@ -2658,15 +2649,11 @@ public operator fun <T> Sequence<T>.minus(elements: Iterable<T>): Sequence<T> {
* the resulting sequence. Changing any of them between successive calls to `iterator` may affect the result.
*
* The operation is _intermediate_ for this sequence and _terminal_ and _stateful_ for the [elements] sequence.
*
* 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> {
override fun iterator(): Iterator<T> {
val other = elements.convertToSetForSetOperation()
val other = elements.toList()
if (other.isEmpty())
return this@minus.iterator()
else
+1 -13
View File
@@ -32,10 +32,6 @@ public operator fun <T> Set<T>.minus(element: T): Set<T> {
* Returns a set containing all elements of the original set except the elements contained in the given [elements] array.
*
* The returned set preserves the element iteration order of the original set.
*
* 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,13 +43,9 @@ public operator fun <T> Set<T>.minus(elements: Array<out T>): Set<T> {
* Returns a set containing all elements of the original set except the elements contained in the given [elements] collection.
*
* The returned set preserves the element iteration order of the original set.
*
* 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)
val other = elements.convertToListIfNotCollection()
if (other.isEmpty())
return this.toSet()
if (other is Set)
@@ -67,10 +59,6 @@ public operator fun <T> Set<T>.minus(elements: Iterable<T>): Set<T> {
* Returns a set containing all elements of the original set except the elements contained in the given [elements] sequence.
*
* The returned set preserves the element iteration order of the original set.
*
* 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)