Optimize formatter use

This commit is contained in:
Syer10
2021-11-07 14:50:31 -05:00
parent 3b51829b35
commit 54c9a10d6b
2 changed files with 12 additions and 14 deletions

View File

@@ -52,17 +52,17 @@ class XmlResourceBundle internal constructor(internal val lookup: ConcurrentHash
private fun String.replaceAndroid() = replace("\\n", "%n")
fun getStringA(key: String): String {
return Formatter().format(getString(key).replaceAndroid())
.let { formatter ->
formatter.toString().also { formatter.close() }
}
return Formatter().use {
it.format(getString(key).replaceAndroid())
.toString()
}
}
fun getString(key: String, vararg replacements: Any?): String {
return Formatter().format(getString(key).replaceAndroid(), *replacements)
.let { formatter ->
formatter.toString().also { formatter.close() }
}
return Formatter().use {
it.format(getString(key).replaceAndroid(), *replacements)
.toString()
}
}
companion object {

View File

@@ -127,12 +127,10 @@ sealed class SourceSettingsView<T, R : Any?> {
}
}
fun withFormat(text: String, value: Any?): String {
return Formatter().format(text, value)
.let { formatter ->
formatter.toString()
.also { formatter.close() }
}
private fun withFormat(text: String, value: Any?): String {
return Formatter().use {
it.format(text, value).toString()
}
}
fun SourceSettingsView(index: Int, preference: SourcePreference): SourceSettingsView<*, *> {