4 ms·
But does .forEach compile to an efficient for-loop in Kotlin?
by sdegutis 10y ago
But does .forEach compile to an efficient for-loop in Kotlin?
- nostrademons 10y agoNot completely sure about the internals of the Kotlin compiler, but I believe it does. You can do a non-local return (i.e. return from the top-level function, not the lambda passed to .forEach) from inside them. This would be very difficult if the body were not inlined, because you'd need to store a lexical stack of return addresses and ensure that the closure never escapes the HOF. (I think it actually does perform this escape analysis; I've gotten error messages before when trying to pass a lambda with a non-local return into a functional argument that wasn't one of the basic collection iterators.)
- deleted 10y ago[deleted]