using generic list for the circular cache instead of a fixed string array

This commit is contained in:
Adam Brown 2021-10-14 12:24:06 +01:00
parent 10b753ad61
commit 84b44f6093
2 changed files with 5 additions and 5 deletions

View File

@ -19,14 +19,14 @@ package im.vector.app.features.notifications
/**
* A FIFO circular buffer of strings
*/
class CircularStringCache(cacheSize: Int) {
class CircularCache<T>(cacheSize: Int) {
private val cache = Array(cacheSize) { "" }
private val cache = ArrayList<T>(initialCapacity = cacheSize)
private var writeIndex = 0
fun contains(key: String): Boolean = cache.contains(key)
fun contains(key: T): Boolean = cache.contains(key)
fun put(key: String) {
fun put(key: T) {
if (writeIndex == cache.size - 1) {
writeIndex = 0
}

View File

@ -89,7 +89,7 @@ class NotificationDrawerManager @Inject constructor(private val context: Context
* Acts as a notification debouncer to stop already dismissed push notifications from
* displaying again when the /sync response is delayed.
*/
private val seenEventIds = CircularStringCache(cacheSize = 25)
private val seenEventIds = CircularCache<String>(cacheSize = 25)
/**
Should be called as soon as a new event is ready to be displayed.