mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-21 15:05:19 +00:00
Add LruCache and thread-safety
This commit is contained in:
parent
fa0abef243
commit
f9ace6a9b9
@ -1,6 +1,7 @@
|
||||
package org.session.libsignal.utilities
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.util.LruCache
|
||||
|
||||
/**
|
||||
* Create a Snode from a "-" delimited String if valid, null otherwise.
|
||||
@ -39,10 +40,11 @@ class Snode(val address: String, val port: Int, val publicKeySet: KeySet?, val v
|
||||
override fun toString(): String = "$address:$port"
|
||||
|
||||
companion object {
|
||||
private val CACHE = mutableMapOf<String, Version>()
|
||||
private val CACHE = LruCache<String, Version>(100)
|
||||
|
||||
@SuppressLint("NotConstructor")
|
||||
fun Version(value: String) = CACHE[value] ?: Snode.Version(value).also { CACHE[value] = it }
|
||||
@Synchronized
|
||||
fun Version(value: String) = CACHE[value] ?: Snode.Version(value).also { CACHE.put(value, it) }
|
||||
|
||||
fun Version(parts: List<Int>) = Version(parts.joinToString("."))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user