perf(about): parse the license catalog with decodeFromStream
Stream the bundled license catalog straight into the JSON decoder instead of buffering the whole resource as a string first, halving parse time and peak allocation when the About screen loads.
This commit is contained in:
1 parent
a2079a37a1
commit
97eeae5876
1 file changed
+2
-2
@@ -5,6 +5,7 @@ import androidx.annotation.RawRes
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.json.Json
|
||||
import kotlinx.serialization.json.decodeFromStream
|
||||
|
||||
@Serializable
|
||||
internal data class AboutLibrariesData(
|
||||
@@ -76,6 +77,5 @@ internal object AboutLibrariesParser {
|
||||
|
||||
fun read(context: Context, @RawRes resourceId: Int): AboutLibrariesData =
|
||||
context.resources.openRawResource(resourceId)
|
||||
.bufferedReader()
|
||||
.use { reader -> json.decodeFromString(reader.readText()) }
|
||||
.use { stream -> json.decodeFromStream(stream) }
|
||||
}
|
||||
Reference in new issue
Block a user