mirror of
https://github.com/ReVanced/revanced-patcher.git
synced 2024-11-10 01:02:22 +01:00
feat: Minor refactor and return proxy, if class has been proxied already
This commit is contained in:
parent
6bc4e7eab7
commit
2d3c61113d
3 changed files with 11 additions and 7 deletions
|
@ -33,7 +33,7 @@ class Patcher(
|
|||
// TODO: the iterator would return the proxied class matching the current index of the list
|
||||
// TODO: instead of the original class
|
||||
for (classProxy in cache.classProxy) {
|
||||
if (!classProxy.proxyused) continue
|
||||
if (!classProxy.proxyUsed) continue
|
||||
// TODO: merge this class with cache.classes somehow in an iterator
|
||||
classProxy.mutatedClass
|
||||
}
|
||||
|
|
|
@ -8,11 +8,15 @@ class Cache(
|
|||
internal val classes: Set<ClassDef>,
|
||||
val resolvedMethods: MethodMap
|
||||
) {
|
||||
internal val classProxy = mutableListOf<ClassProxy>()
|
||||
internal val classProxy = mutableSetOf<ClassProxy>()
|
||||
|
||||
fun findClass(predicate: (ClassDef) -> Boolean): ClassProxy? {
|
||||
// if a class has been found with the given predicate,
|
||||
val foundClass = classes.singleOrNull(predicate) ?: return null
|
||||
// if we already proxied the class matching the predicate,
|
||||
val proxiedClass = classProxy.singleOrNull{classProxy -> predicate(classProxy.immutableClass)}
|
||||
// return that proxy
|
||||
if (proxiedClass != null) return proxiedClass
|
||||
// else search the original class list
|
||||
val foundClass = classes.singleOrNull(predicate) ?: return null
|
||||
// create a class proxy with the index of the class in the classes list
|
||||
// TODO: There might be a more elegant way to the comment above
|
||||
val classProxy = ClassProxy(foundClass, classes.indexOf(foundClass))
|
||||
|
|
|
@ -8,12 +8,12 @@ class ClassProxy(
|
|||
val immutableClass: ClassDef,
|
||||
val originalClassIndex: Int,
|
||||
) {
|
||||
internal var proxyused = false
|
||||
internal var proxyUsed = false
|
||||
internal lateinit var mutatedClass: MutableClass
|
||||
|
||||
fun resolve(): MutableClass {
|
||||
if (!proxyused) {
|
||||
proxyused = true
|
||||
if (!proxyUsed) {
|
||||
proxyUsed = true
|
||||
mutatedClass = MutableClass(immutableClass)
|
||||
}
|
||||
return mutatedClass
|
||||
|
|
Loading…
Reference in a new issue