mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2025-09-30 19:23:17 +02:00
Fixes #993
This commit is contained in:
@@ -26,21 +26,35 @@ import com.vitorpamplona.amethyst.commons.richtext.RichTextViewerState
|
|||||||
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
import com.vitorpamplona.quartz.events.ImmutableListOfLists
|
||||||
|
|
||||||
object CachedRichTextParser {
|
object CachedRichTextParser {
|
||||||
val richTextCache = LruCache<String, RichTextViewerState>(50)
|
val richTextCache = LruCache<Int, RichTextViewerState>(50)
|
||||||
|
|
||||||
fun getCached(content: String): RichTextViewerState? = richTextCache[content]
|
// fun getCached(content: String): RichTextViewerState? = richTextCache[content]
|
||||||
|
|
||||||
|
fun hashCodeCache(
|
||||||
|
content: String,
|
||||||
|
tags: ImmutableListOfLists<String>,
|
||||||
|
callbackUri: String?,
|
||||||
|
): Int {
|
||||||
|
var result = content.hashCode()
|
||||||
|
result = 31 * result + tags.lists.hashCode()
|
||||||
|
if (callbackUri != null) {
|
||||||
|
result = 31 * result + callbackUri.hashCode()
|
||||||
|
}
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
fun parseText(
|
fun parseText(
|
||||||
content: String,
|
content: String,
|
||||||
tags: ImmutableListOfLists<String>,
|
tags: ImmutableListOfLists<String>,
|
||||||
callbackUri: String? = null,
|
callbackUri: String? = null,
|
||||||
): RichTextViewerState {
|
): RichTextViewerState {
|
||||||
val cached = richTextCache[content]
|
val key = hashCodeCache(content, tags, callbackUri)
|
||||||
|
val cached = richTextCache[key]
|
||||||
return if (cached != null) {
|
return if (cached != null) {
|
||||||
cached
|
cached
|
||||||
} else {
|
} else {
|
||||||
val newUrls = RichTextParser().parseText(content, tags, callbackUri)
|
val newUrls = RichTextParser().parseText(content, tags, callbackUri)
|
||||||
richTextCache.put(content, newUrls)
|
richTextCache.put(key, newUrls)
|
||||||
newUrls
|
newUrls
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user