[译]Android性能优化-Kotlin优化isBlank
本地首发地址 https://h89.cn/archives/189.html
最新更新地址 https://gitee.com/chenjim/chenjimblog
原文地址 https://www.romainguy.dev/posts/2024/speeding-up-isblank/
最近在优化 Jetpack Compose 运行时的部分时,偶然发现了一个看似无害的 API isBlank() 。如果调用的字符串为空或仅由空格字符组成,则此 API 将返回 true 。
但它真的无害吗?让我们看一下 JVM 实现,以更好地了解它的作用:
public actual fun CharSequence.isBlank(): Boolean =
length == 0 || indices.all { this[i