Remove brittle ‘contains’ optimization in minus/removeAll/retainAll #KT-45438
This commit is contained in:
committed by
Ilya Gorbunov
parent
fbc43cbebe
commit
94b371af5b
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user