is there a performance impact to using `when` for ...
# announcements
h
is there a performance impact to using
when
for only 2 cases instead of `if`/`else`?
d
If you're using conditions as the cases like,
Copy code
when {
   x == 3 -> ....
   y < 7 -> .....
}
then it doesn't matter, they'll probably compile to the same thing. If you using values as the cases like,
Copy code
when(x) {
1 -> ...
2 -> ...
}
you'll have to look at the byte code.
Although I reckon the compiler is smart enough, that it doesn't matter.
k
Tools > Show Kotlin bytecode > Decompile
is you friend!
😍 1