perf(AnalyzeUrl):skip init block when mUrl is DataURL

pull/1786/head
Xwite 3 years ago
parent 69dfea0218
commit cfa98112ce
  1. 5
      app/src/main/java/io/legado/app/help/glide/ImageLoader.kt
  2. 6
      app/src/main/java/io/legado/app/model/analyzeRule/AnalyzeUrl.kt
  3. 6
      app/src/main/java/io/legado/app/utils/StringExtensions.kt

@ -6,8 +6,8 @@ import android.graphics.drawable.Drawable
import android.net.Uri
import androidx.annotation.DrawableRes
import com.bumptech.glide.RequestBuilder
import io.legado.app.constant.AppPattern.dataUriRegex
import io.legado.app.utils.isAbsUrl
import io.legado.app.utils.isDataUrl
import io.legado.app.utils.isContentScheme
import java.io.File
@ -20,7 +20,7 @@ object ImageLoader {
fun load(context: Context, path: String?): RequestBuilder<Drawable> {
return when {
path.isNullOrEmpty() -> GlideApp.with(context).load(path)
dataUriRegex.find(path) != null -> GlideApp.with(context).load(path)
path.isDataUrl() -> GlideApp.with(context).load(path)
path.isAbsUrl() -> GlideApp.with(context).load(path)
path.isContentScheme() -> GlideApp.with(context).load(Uri.parse(path))
else -> kotlin.runCatching {
@ -34,6 +34,7 @@ object ImageLoader {
fun loadBitmap(context: Context, path: String?): RequestBuilder<Bitmap> {
return when {
path.isNullOrEmpty() -> GlideApp.with(context).asBitmap().load(path)
path.isDataUrl() -> GlideApp.with(context).asBitmap().load(path)
path.isAbsUrl() -> GlideApp.with(context).asBitmap().load(path)
path.isContentScheme() -> GlideApp.with(context).asBitmap().load(Uri.parse(path))
else -> kotlin.runCatching {

@ -71,6 +71,7 @@ class AnalyzeUrl(
private var webJs: String? = null
init {
if (!mUrl.isDataUrl()) {
val urlMatcher = paramPattern.matcher(baseUrl)
if (urlMatcher.find()) baseUrl = baseUrl.substring(0, urlMatcher.start())
(headerMapF ?: source?.getHeaderMap(true))?.let {
@ -82,6 +83,7 @@ class AnalyzeUrl(
}
initUrl()
}
}
/**
* 处理url
@ -457,10 +459,9 @@ class AnalyzeUrl(
* 访问网站,返回ByteArray
*/
suspend fun getByteArrayAwait(): ByteArray {
val concurrentRecord = fetchStart()
@Suppress("RegExpRedundantEscape")
val dataUriFindResult = dataUriRegex.find(urlNoQuery)
val concurrentRecord = fetchStart()
setCookie(source?.getKey())
@Suppress("BlockingMethodInNonBlockingContext")
if (dataUriFindResult != null) {
val dataUriBase64 = dataUriFindResult.groupValues[1]
@ -468,6 +469,7 @@ class AnalyzeUrl(
fetchEnd(concurrentRecord)
return byteArray
} else {
setCookie(source?.getKey())
val byteArray = getProxyClient(proxy).newCallResponseBody(retry) {
addHeaders(headerMap)
when (method) {

@ -2,6 +2,7 @@
package io.legado.app.utils
import io.legado.app.constant.AppPattern.dataUriRegex
import android.icu.text.Collator
import android.icu.util.ULocale
import android.net.Uri
@ -25,6 +26,11 @@ fun String?.isAbsUrl() =
it.startsWith("http://", true) || it.startsWith("https://", true)
} ?: false
fun String?.isDataUrl() =
this?.let {
dataUriRegex.matches(it)
} ?: false
fun String?.isJson(): Boolean =
this?.run {
val str = this.trim()

Loading…
Cancel
Save