diff --git a/libraries/stdlib/common/src/generated/_Collections.kt b/libraries/stdlib/common/src/generated/_Collections.kt index a52f17295f1..13fe1a400af 100644 --- a/libraries/stdlib/common/src/generated/_Collections.kt +++ b/libraries/stdlib/common/src/generated/_Collections.kt @@ -1921,6 +1921,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. */ public operator fun Iterable.minus(elements: Array): List { if (elements.isEmpty()) return this.toList() @@ -1930,6 +1933,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. */ public operator fun Iterable.minus(elements: Iterable): List { val other = elements.convertToSetForSetOperationWith(this) @@ -1940,6 +1946,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. */ public operator fun Iterable.minus(elements: Sequence): List { val other = elements.toHashSet() diff --git a/libraries/stdlib/common/src/generated/_Sequences.kt b/libraries/stdlib/common/src/generated/_Sequences.kt index 5f5af922785..28e535b03f5 100644 --- a/libraries/stdlib/common/src/generated/_Sequences.kt +++ b/libraries/stdlib/common/src/generated/_Sequences.kt @@ -1430,6 +1430,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. * * The operation is _intermediate_ and _stateful_. */ @@ -1448,6 +1451,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. * * The operation is _intermediate_ and _stateful_. */ @@ -1470,6 +1476,9 @@ public operator fun Sequence.minus(elements: Iterable): Sequence { * 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. + * + * 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. */ 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 5d22edf5501..236e71e0d17 100644 --- a/libraries/stdlib/common/src/generated/_Sets.kt +++ b/libraries/stdlib/common/src/generated/_Sets.kt @@ -30,6 +30,9 @@ public operator fun Set.minus(element: T): Set { * 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. + * + * 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. */ public operator fun Set.minus(elements: Array): Set { val result = LinkedHashSet(this) @@ -41,6 +44,9 @@ public operator fun Set.minus(elements: Array): Set { * 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. + * + * 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. */ public operator fun Set.minus(elements: Iterable): Set { val other = elements.convertToSetForSetOperationWith(this) @@ -57,6 +63,9 @@ public operator fun Set.minus(elements: Iterable): Set { * 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. + * + * 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. */ public operator fun Set.minus(elements: Sequence): Set { val result = LinkedHashSet(this) diff --git a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt index 35dadcc786a..633ce923d36 100644 --- a/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt +++ b/libraries/tools/kotlin-stdlib-gen/src/templates/Generators.kt @@ -358,13 +358,18 @@ 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. + """ val f_minus_iterable = fn("minus(elements: Iterable)") { include(Iterables, Sets, Sequences) } builder { operator(true) - doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection." } + doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] collection.\n" } returns("List") specialFor(Sets, Sequences) { returns("SELF") } body { @@ -425,6 +430,9 @@ object Generators : TemplateGroupBase() { } } + doc { + doc + elementsConversionClause(Iterables) + } } val f_minus_array = fn("minus(elements: Array)") { @@ -432,7 +440,7 @@ object Generators : TemplateGroupBase() { } builder { operator(true) - doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] array." } + doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] array.\n" } returns("List") specialFor(Sets, Sequences) { returns("SELF") } body { @@ -481,6 +489,9 @@ object Generators : TemplateGroupBase() { """ } } + doc { + doc + elementsConversionClause(ArraysOfObjects) + } } val f_minus_sequence = fn("minus(elements: Sequence)") { @@ -488,7 +499,7 @@ object Generators : TemplateGroupBase() { } builder { operator(true) - doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence." } + doc { "Returns a list containing all elements of the original collection except the elements contained in the given [elements] sequence.\n" } returns("List") specialFor(Sets, Sequences) { returns("SELF") } body { @@ -542,6 +553,9 @@ object Generators : TemplateGroupBase() { """ } } + doc { + doc + elementsConversionClause(Sequences) + } } val f_partition = fn("partition(predicate: (T) -> Boolean)") {