Remove brittle ‘contains’ optimization in minus/removeAll/retainAll #KT-45438

This commit is contained in:
Abduqodiri Qurbonzoda
2021-07-12 13:56:33 +03:00
committed by Ilya Gorbunov
parent fbc43cbebe
commit 94b371af5b
10 changed files with 88 additions and 37 deletions
@@ -2995,7 +2995,7 @@ public operator fun <T> Iterable<T>.minus(element: T): List<T> {
*/
public operator fun <T> Iterable<T>.minus(elements: Array<out T>): List<T> {
if (elements.isEmpty()) return this.toList()
val other = elements.toHashSet()
val other = elements.convertToSetForSetOperation()
return this.filterNot { it in other }
}
@@ -3019,7 +3019,7 @@ public operator fun <T> Iterable<T>.minus(elements: Iterable<T>): List<T> {
* a correct and stable implementation of `hashCode()` that doesn't change between successive invocations.
*/
public operator fun <T> Iterable<T>.minus(elements: Sequence<T>): List<T> {
val other = elements.toHashSet()
val other = elements.convertToSetForSetOperation()
if (other.isEmpty())
return this.toList()
return this.filterNot { it in other }
@@ -2449,7 +2449,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.toHashSet()
val other = elements.convertToSetForSetOperation()
return this@minus.filterNot { it in other }.iterator()
}
}
@@ -2492,7 +2492,7 @@ public operator fun <T> Sequence<T>.minus(elements: Iterable<T>): Sequence<T> {
public operator fun <T> Sequence<T>.minus(elements: Sequence<T>): Sequence<T> {
return object: Sequence<T> {
override fun iterator(): Iterator<T> {
val other = elements.toHashSet()
val other = elements.convertToSetForSetOperation()
if (other.isEmpty())
return this@minus.iterator()
else