Release 5.2.2 - Kotlin API Optimize forEachOf with inline delegation and identity function
· One min read
Optimizing both forEachOf and forEachIndexedOf with inline delegation and
identity function.
Refactored the overloads to improve performance and reduce unnecessary runtime
overhead.
The iterable-based overload now uses Kotlin's inline modifier and delegates
through the existing implementation using an identity function. This removes the
need for an additional non-inline wrapper function while preserving the original
API and its extension-lambda syntax.
The changes aim to:
- Inline the overload delegation to reduce function-call overhead.
- Use
identity<M>()instead of allocating a new identity lambda at the call site. - Preserve the
crossinlinebehavior of theitemTemplateparameter. - Keep both overloads consistent while reusing the existing iteration implementation.
- Maintain the existing type constraints and usage semantics.
Overall, this refactoring simplifies the delegation path and gives the Kotlin compiler more opportunities to optimize lambda handling and function calls, particularly in frequently executed rendering and DSL operations.