Avoid allocation?

I'm not sure kotlin compiler will optimize this
This commit is contained in:
tarsin committed 2023-05-14 18:24:43 +08:00
1 parent 196190314b
commit c4ff48f60f
1 file changed
+4 -1
@@ -30,9 +30,12 @@ fun ImageRequest.Builder.ehPreviewKey(key: GalleryPreview) = apply {
size(Size.ORIGINAL)
}
private val stubResult = DecodeResult(ColorDrawable(Color.BLACK), false)
private val stubFactory = Decoder { stubResult }
fun ImageRequest.Builder.justDownload() = apply {
memoryCachePolicy(CachePolicy.DISABLED)
decoderFactory { _, _, _ -> Decoder { DecodeResult(ColorDrawable(Color.BLACK), false) } }
decoderFactory { _, _, _ -> stubFactory }
}
inline fun Context.imageRequest(key: GalleryPreview, builder: ImageRequest.Builder.() -> Unit = {}) = ImageRequest.Builder(this).ehPreviewKey(key).apply(builder).build()