Skip to content

Commit 3bd633a

Browse files
committed
Optimize localedOrNull
1 parent 7d806ff commit 3bd633a

File tree

1 file changed

+3
-3
lines changed
  • core/src/main/kotlin/io/github/rothes/esu/core/user

1 file changed

+3
-3
lines changed

core/src/main/kotlin/io/github/rothes/esu/core/user/User.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ interface User {
5454
fun <V, R> localedOrNull(langMap: Map<String, V>, block: (V) -> R?): R? {
5555
val lang = language
5656
return langMap[lang]?.let(block)
57-
// If this locale is not found, try the same language.
58-
?: lang?.split('_')?.get(0)?.let { language ->
57+
// If this locale is not found, try the same language.
58+
?: lang?.substringBefore('_')?.let { language ->
5959
val lang = language + '_'
60-
langMap.entries.filter { it.key.startsWith(lang) }.firstNotNullOfOrNull { block(it.value) }
60+
langMap.entries.find { it.key.startsWith(lang) }?.let { block(it.value) }
6161
}
6262
// Still? Use the server default locale instead.
6363
?: langMap[EsuConfig.get().locale]?.let(block)

0 commit comments

Comments
 (0)