mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2026-01-19 17:33:56 +00:00
fix: Do not create a new matcher instance if provided with one
This commit is contained in:
@@ -164,7 +164,7 @@ class Fingerprint internal constructor(
|
||||
is StringFilter -> {
|
||||
val string = instruction.stringReference?.string ?: return false
|
||||
|
||||
val filterString = string()
|
||||
val filterString = stringValue
|
||||
when (comparison) {
|
||||
StringComparisonType.EQUALS -> string == filterString
|
||||
StringComparisonType.CONTAINS -> string.contains(filterString)
|
||||
@@ -212,7 +212,7 @@ class Fingerprint internal constructor(
|
||||
it.filters.filterIsInstance<StringFilter>()
|
||||
})
|
||||
)
|
||||
}.map { it.string() } + (strings ?: emptyList())
|
||||
}.map { it.stringValue } + (strings ?: emptyList())
|
||||
|
||||
val method = if (allStrings.isNotEmpty())
|
||||
context.firstMethodOrNull(strings = allStrings.toTypedArray()) { match() } ?:
|
||||
|
||||
@@ -844,7 +844,7 @@ class StringFilter internal constructor(
|
||||
/**
|
||||
* Store the lambda value instead of calling it more than once.
|
||||
*/
|
||||
private val stringValue: String by lazy (string)
|
||||
internal val stringValue: String by lazy (string)
|
||||
|
||||
override fun matches(
|
||||
enclosingMethod: Method,
|
||||
|
||||
@@ -229,7 +229,7 @@ fun <T> Iterable<T>.matchIndexed(build: IndexedMatcher<T>.() -> Unit) =
|
||||
|
||||
context(_: MatchContext)
|
||||
operator fun <T> IndexedMatcher<T>.invoke(iterable: Iterable<T>, key: String, builder: IndexedMatcher<T>.() -> Unit) =
|
||||
remember(key) { IndexedMatcher<T>().apply(builder) }(iterable)
|
||||
remember(key) { apply(builder) }(iterable)
|
||||
|
||||
context(_: MatchContext)
|
||||
fun <T> Iterable<T>.matchIndexed(key: String, build: IndexedMatcher<T>.() -> Unit) =
|
||||
@@ -241,12 +241,11 @@ abstract class Matcher<T, U> : MutableList<U> by mutableListOf() {
|
||||
|
||||
abstract operator fun invoke(haystack: Iterable<T>): Boolean
|
||||
|
||||
class MatchContext internal constructor() : MutableMap<String, Any> by mutableMapOf() {
|
||||
}
|
||||
class MatchContext internal constructor() : MutableMap<Any, Any> by mutableMapOf()
|
||||
}
|
||||
|
||||
context(context: MatchContext)
|
||||
inline fun <reified V : Any> remember(key: String, defaultValue: () -> V) =
|
||||
inline fun <reified V : Any> remember(key: Any, defaultValue: () -> V) =
|
||||
context[key] as? V ?: defaultValue().also { context[key] = it }
|
||||
|
||||
class IndexedMatcher<T>() : Matcher<T, T.() -> Boolean>() {
|
||||
@@ -257,6 +256,7 @@ class IndexedMatcher<T>() : Matcher<T, T.() -> Boolean>() {
|
||||
private var currentIndex = -1
|
||||
|
||||
override fun invoke(haystack: Iterable<T>): Boolean {
|
||||
// Defensive, in case haystack is not a list.
|
||||
val hayList = haystack as? List<T> ?: haystack.toList()
|
||||
|
||||
_indices.clear()
|
||||
@@ -278,7 +278,7 @@ class IndexedMatcher<T>() : Matcher<T, T.() -> Boolean>() {
|
||||
currentIndex = subIndex
|
||||
val element = hayList[subIndex]
|
||||
if (this[predicateIndex](element)) {
|
||||
tempIndices.add(subIndex)
|
||||
tempIndices += subIndex
|
||||
lastMatchedIndex = subIndex
|
||||
predicateMatched = true
|
||||
subIndex++
|
||||
@@ -296,7 +296,7 @@ class IndexedMatcher<T>() : Matcher<T, T.() -> Boolean>() {
|
||||
}
|
||||
|
||||
if (matchedAll) {
|
||||
_indices.addAll(tempIndices)
|
||||
_indices += tempIndices
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -304,6 +304,7 @@ class IndexedMatcher<T>() : Matcher<T, T.() -> Boolean>() {
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
fun first(predicate: T.() -> Boolean) = add {
|
||||
if (lastMatchedIndex != -1) false
|
||||
else predicate()
|
||||
|
||||
@@ -69,7 +69,7 @@ class Patcher(private val config: PatcherConfig) : Closeable {
|
||||
|
||||
// Recursively execute all dependency patches.
|
||||
dependencies.forEach { dependency ->
|
||||
dependency.execute(executedPatches).exception?.let {
|
||||
dependency.execute(executedPatches).exception?.let{
|
||||
return PatchResult(
|
||||
this,
|
||||
PatchException(
|
||||
|
||||
Reference in New Issue
Block a user