mirror of
https://github.com/jlengrand/kotlin.git
synced 2026-05-08 15:53:19 +00:00
In code like 'a?.b == 42', we can immediately generate equality comparison result when receiver is null (false for '==', true for '!='), since the primitive value is definitely non-null. Otherwise unnecessary boxing/unboxing is generated to handle possibly null result of 'a?.b'.
24 lines
523 B
Kotlin
Vendored
24 lines
523 B
Kotlin
Vendored
fun Long.id() = this
|
|
|
|
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
|
|
|
fun doSimple1(s: String?) = s?.length == 3
|
|
|
|
fun doLongReceiver1(x: Long) = x?.id() == 3L
|
|
|
|
fun doChain1(s: String?) = s?.drop2()?.length == 1
|
|
|
|
fun doIf1(s: String?) =
|
|
if (s?.length == 1) "A" else "B"
|
|
|
|
fun doSimple2(s: String?) = 3 == s?.length
|
|
|
|
fun doLongReceiver2(x: Long) = 3L == x?.id()
|
|
|
|
fun doChain2(s: String?) = 1 == s?.drop2()?.length
|
|
|
|
fun doIf2(s: String?) =
|
|
if (1 == s?.length) "A" else "B"
|
|
|
|
// 0 valueOf
|