Make SSD box type cache non-null
ober
b5ec687c428a45afa47f83b309797f08b2dfefac
--- a/templates/ssd-review.ss +++ b/templates/ssd-review.ss @@ -6,7 +6,7 @@ (typed-library (com sfb ssdreview) (export make-BoxType BoxType? BoxType-id BoxType-name box-type-display boxTypeDisplays boxTypeById boxTypeDisplayById - cachedBoxTypesPresent cachedBoxTypesOrEmpty addNullableBoxType) + addNullableBoxType) (type Int32) (record BoxType ((id : String) @@ -35,12 +35,6 @@ (if (nullable-null? box) id (box-type-display (nullable-get box))))) - (def (cachedBoxTypesPresent (items : (Nullable (MutableList BoxType)))) : Bool - (not (nullable-null? items))) - (def (cachedBoxTypesOrEmpty (items : (Nullable (MutableList BoxType)))) : (MutableList BoxType) - (if (nullable-null? items) - (mutable-list-empty BoxType) - (nullable-get items))) (def (addNullableBoxType (items : (MutableList BoxType)) (box : (Nullable BoxType))) : Unit (if (nullable-null? box) @@ -6228,10 +6222,11 @@ "import android.content.Context" "" "object BoxTypes {" - " private var cache: MutableList<BoxType>? = null" + " private var cacheLoaded = false" + " private var cache: MutableList<BoxType> = mutableListOf()" "" " fun load(context: Context): List<BoxType> {" - " if (cachedBoxTypesPresent(cache)) return cachedBoxTypesOrEmpty(cache)" + " if (cacheLoaded) return cache" " val items = mutableListOf<BoxType>()" " context.assets.open(\"box_types.csv\").bufferedReader().useLines { lines ->" " lines.drop(1).forEach { line ->" @@ -6239,6 +6234,7 @@ " }" " }" " cache = items" + " cacheLoaded = true" " return items" " }" ""