优化
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
**2023/01/10**
|
||||
|
||||
* 其他一些有分组的地方也支持独立排序
|
||||
* 优化搜索,优化缓存,尝试解决部分书源占用内存过大导致OOM
|
||||
* 修复中文AndroidZipFile不能读取非ASCII字符文件名 by ag2s20150909
|
||||
* 其它一些优化
|
||||
|
||||
|
||||
@@ -5,12 +5,23 @@ import io.legado.app.data.appDb
|
||||
import io.legado.app.data.entities.Cache
|
||||
import io.legado.app.model.analyzeRule.QueryTTF
|
||||
import io.legado.app.utils.ACache
|
||||
import io.legado.app.utils.memorySize
|
||||
|
||||
@Suppress("unused")
|
||||
object CacheManager {
|
||||
|
||||
private val queryTTFMap = hashMapOf<String, Pair<Long, QueryTTF>>()
|
||||
private val memoryLruCache = object : LruCache<String, String>(100) {}
|
||||
|
||||
/**
|
||||
* 最多只缓存50M的数据,防止OOM
|
||||
*/
|
||||
private val memoryLruCache = object : LruCache<String, String>(1024 * 1024 * 50) {
|
||||
|
||||
override fun sizeOf(key: String, value: String): Int {
|
||||
return value.memorySize()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* saveTime 单位为秒
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.icu.text.Collator
|
||||
import android.icu.util.ULocale
|
||||
import android.net.Uri
|
||||
import android.text.Editable
|
||||
import cn.hutool.core.lang.Validator
|
||||
import io.legado.app.constant.AppPattern.dataUriRegex
|
||||
import java.io.File
|
||||
import java.util.*
|
||||
@@ -90,6 +89,14 @@ fun String.cnCompare(other: String): Int {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串所占内存大小
|
||||
*/
|
||||
fun String?.memorySize(): Int {
|
||||
this ?: return 0
|
||||
return 40 + 2 * length
|
||||
}
|
||||
|
||||
/**
|
||||
* 将字符串拆分为单个字符,包含emoji
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user