diff --git a/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt b/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt index 1765fb9b..d0d37a2e 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/ClassProxy.kt @@ -19,7 +19,7 @@ class ClassProxy( /** * Creates and returns a mutable clone of the original class - * A patch should always use the original immutable class reference to avoid unnucessary allocations for the mutable class + * A patch should always use the original immutable class reference to avoid unnecessary allocations for the mutable class */ fun resolve(): MutableClass { if (!proxyUsed) { diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt index 09b15796..927f3593 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableAnnotation.kt @@ -7,14 +7,14 @@ import org.jf.dexlib2.iface.Annotation class MutableAnnotation(annotation: Annotation) : BaseAnnotation() { private val visibility = annotation.visibility private val type = annotation.type - private val elements = annotation.elements.map { element -> element.toMutable() }.toMutableSet() + private val _elements by lazy { annotation.elements.map { element -> element.toMutable() }.toMutableSet() } override fun getType(): String { return type } override fun getElements(): MutableSet { - return elements + return _elements } override fun getVisibility(): Int { diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt index 87420e61..4b4f8070 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableClass.kt @@ -13,20 +13,18 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() { private var accessFlags = classDef.accessFlags private var superclass = classDef.superclass - private val interfaces = classDef.interfaces.toMutableList() - private val annotations = classDef.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() + private val _interfaces by lazy { classDef.interfaces.toMutableList() } + private val _annotations by lazy { classDef.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() } // Methods - private val methods = classDef.methods.map { method -> method.toMutable() }.toMutableSet() - private val directMethods = classDef.directMethods.map { directMethod -> directMethod.toMutable() }.toMutableSet() - private val virtualMethods = - classDef.virtualMethods.map { virtualMethod -> virtualMethod.toMutable() }.toMutableSet() + private val _methods by lazy { classDef.methods.map { method -> method.toMutable() }.toMutableSet() } + private val _directMethods by lazy { classDef.directMethods.map { directMethod -> directMethod.toMutable() }.toMutableSet() } + private val _virtualMethods by lazy { classDef.virtualMethods.map { virtualMethod -> virtualMethod.toMutable() }.toMutableSet() } // Fields - private val fields = classDef.fields.map { field -> field.toMutable() }.toMutableSet() - private val staticFields = classDef.staticFields.map { staticField -> staticField.toMutable() }.toMutableSet() - private val instanceFields = - classDef.instanceFields.map { instanceFields -> instanceFields.toMutable() }.toMutableSet() + private val _fields by lazy { classDef.fields.map { field -> field.toMutable() }.toMutableSet() } + private val _staticFields by lazy { classDef.staticFields.map { staticField -> staticField.toMutable() }.toMutableSet() } + private val _instanceFields by lazy { classDef.instanceFields.map { instanceFields -> instanceFields.toMutable() }.toMutableSet() } fun setType(type: String) { this.type = type @@ -61,34 +59,34 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() { } override fun getInterfaces(): MutableList { - return interfaces + return _interfaces } override fun getAnnotations(): MutableSet { - return annotations + return _annotations } override fun getStaticFields(): MutableSet { - return staticFields + return _staticFields } override fun getInstanceFields(): MutableSet { - return instanceFields + return _instanceFields } override fun getFields(): MutableSet { - return fields + return _fields } override fun getDirectMethods(): MutableSet { - return directMethods + return _directMethods } override fun getVirtualMethods(): MutableSet { - return virtualMethods + return _virtualMethods } override fun getMethods(): MutableSet { - return methods + return _methods } } \ No newline at end of file diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableEncodedValue.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableEncodedValue.kt index 34f5d835..fbc7101f 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableEncodedValue.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableEncodedValue.kt @@ -11,7 +11,6 @@ class MutableEncodedValue(encodedValue: EncodedValue) : EncodedValue { override fun compareTo(other: EncodedValue): Int { return valueType - other.valueType - } override fun getValueType(): Int { diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt index 512b2cf8..fe8bedd3 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableField.kt @@ -11,10 +11,10 @@ class MutableField(field: Field) : Field, BaseFieldReference() { private var type = field.type private var accessFlags = field.accessFlags private var initialValue = field.initialValue?.toMutable() - private val annotations = field.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() + private val _annotations by lazy { field.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() } fun setDefiningClass(definingClass: String) { - this.definingClass + this.definingClass = definingClass } fun setName(name: String) { @@ -46,7 +46,7 @@ class MutableField(field: Field) : Field, BaseFieldReference() { } override fun getAnnotations(): MutableSet { - return this.annotations + return this._annotations } override fun getAccessFlags(): Int { diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt index a168bd1f..af4d3bc3 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethod.kt @@ -14,9 +14,9 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() { // Create own mutable MethodImplementation (due to not being able to change members like register count) private var implementation = method.implementation?.let { MutableMethodImplementation(it) } - private val annotations = method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() - private val parameters = method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() - private val parameterTypes = method.parameterTypes.toMutableList() + private val _annotations by lazy { method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() } + private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() } + private val _parameterTypes by lazy { method.parameterTypes.toMutableList() } override fun getDefiningClass(): String { return this.definingClass @@ -27,7 +27,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() { } override fun getParameterTypes(): MutableList { - return parameterTypes + return _parameterTypes } override fun getReturnType(): String { @@ -35,7 +35,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() { } override fun getAnnotations(): MutableSet { - return annotations + return _annotations } override fun getAccessFlags(): Int { @@ -43,7 +43,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() { } override fun getParameters(): MutableList { - return parameters + return _parameters } override fun getImplementation(): MutableMethodImplementation? { diff --git a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt index ddef6808..d4594d4f 100644 --- a/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt +++ b/src/main/kotlin/app/revanced/patcher/proxy/mutableTypes/MutableMethodParameter.kt @@ -9,7 +9,7 @@ class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, Base private var type = parameter.type private var name = parameter.name private var signature = parameter.signature - private val annotations = parameter.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() + private val _annotations by lazy { parameter.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() } override fun getType(): String { return type @@ -24,7 +24,7 @@ class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, Base } override fun getAnnotations(): MutableSet { - return annotations + return _annotations } companion object {