Increasing the speed of the Robohash SVG to buffer function

This commit is contained in:
Vitor Pamplona
2024-02-21 13:51:27 -05:00
parent 0429c4dc3a
commit 4b9a55e178
4 changed files with 64 additions and 43 deletions
@@ -30,9 +30,10 @@ import coil.fetch.Fetcher
import coil.fetch.SourceResult
import coil.request.ImageRequest
import coil.request.Options
import com.vitorpamplona.amethyst.commons.Robohash
import com.vitorpamplona.amethyst.service.checkNotInMainThread
import com.vitorpamplona.quartz.utils.Robohash
import okio.Buffer
import okio.buffer
import okio.source
import java.nio.charset.Charset
@Stable
@@ -43,14 +44,10 @@ class HashImageFetcher(
) : Fetcher {
override suspend fun fetch(): SourceResult {
checkNotInMainThread()
val source =
try {
val buffer = Buffer()
buffer.writeString(
Robohash.assemble(data.toString(), isLightTheme),
Charset.defaultCharset(),
)
buffer
Robohash.assemble(data.toString(), isLightTheme).byteInputStream(Charset.defaultCharset()).source().buffer()
} finally {
}