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.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
|
import kotlinx.serialization.json.decodeFromStream
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
internal data class AboutLibrariesData(
|
internal data class AboutLibrariesData(
|
||||||
@@ -76,6 +77,5 @@ internal object AboutLibrariesParser {
|
|||||||
|
|
||||||
fun read(context: Context, @RawRes resourceId: Int): AboutLibrariesData =
|
fun read(context: Context, @RawRes resourceId: Int): AboutLibrariesData =
|
||||||
context.resources.openRawResource(resourceId)
|
context.resources.openRawResource(resourceId)
|
||||||
.bufferedReader()
|
.use { stream -> json.decodeFromStream(stream) }
|
||||||
.use { reader -> json.decodeFromString(reader.readText()) }
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user