Introduce overloads to check for T? element contained in iterable range in a constant time

#KT-18483
This commit is contained in:
Ilya Gorbunov
2018-09-10 04:18:14 +03:00
parent 64e85e8a0c
commit 1eda3805ec
5 changed files with 102 additions and 0 deletions
@@ -174,6 +174,25 @@ object RangeOps : TemplateGroupBase() {
}
}
val f_contains_nullable = fn("contains(element: T?)") {
include(RangesOfPrimitives, rangePrimitives)
} builder {
since("1.3")
operator()
inlineOnly()
doc {
"""
Returns `true` if this ${f.collection} contains the specified [element].
Always returns `false` if the [element] is `null`.
"""
}
returns("Boolean")
body { "return element != null && contains(element)" }
}
val f_toPrimitiveExactOrNull = fn("to{}ExactOrNull()").byTwoPrimitives {
include(Primitives, numericPermutations)
filter { _, (fromType, toType) -> fromType.capacity > toType.capacity && toType.isIntegral() }