mirror of
https://github.com/revanced/revanced-patcher.git
synced 2025-05-08 08:04:25 +02:00
perf: lazy-ify all mutable clones
This commit is contained in:
parent
bfe4e3e298
commit
d18a3b6a28
@ -19,7 +19,7 @@ class ClassProxy(
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates and returns a mutable clone of the original class
|
* 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 {
|
fun resolve(): MutableClass {
|
||||||
if (!proxyUsed) {
|
if (!proxyUsed) {
|
||||||
|
@ -7,14 +7,14 @@ import org.jf.dexlib2.iface.Annotation
|
|||||||
class MutableAnnotation(annotation: Annotation) : BaseAnnotation() {
|
class MutableAnnotation(annotation: Annotation) : BaseAnnotation() {
|
||||||
private val visibility = annotation.visibility
|
private val visibility = annotation.visibility
|
||||||
private val type = annotation.type
|
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 {
|
override fun getType(): String {
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getElements(): MutableSet<MutableAnnotationElement> {
|
override fun getElements(): MutableSet<MutableAnnotationElement> {
|
||||||
return elements
|
return _elements
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getVisibility(): Int {
|
override fun getVisibility(): Int {
|
||||||
|
@ -13,20 +13,18 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
|
|||||||
private var accessFlags = classDef.accessFlags
|
private var accessFlags = classDef.accessFlags
|
||||||
private var superclass = classDef.superclass
|
private var superclass = classDef.superclass
|
||||||
|
|
||||||
private val interfaces = classDef.interfaces.toMutableList()
|
private val _interfaces by lazy { classDef.interfaces.toMutableList() }
|
||||||
private val annotations = classDef.annotations.map { annotation -> annotation.toMutable() }.toMutableSet()
|
private val _annotations by lazy { classDef.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
||||||
|
|
||||||
// Methods
|
// Methods
|
||||||
private val methods = classDef.methods.map { method -> method.toMutable() }.toMutableSet()
|
private val _methods by lazy { classDef.methods.map { method -> method.toMutable() }.toMutableSet() }
|
||||||
private val directMethods = classDef.directMethods.map { directMethod -> directMethod.toMutable() }.toMutableSet()
|
private val _directMethods by lazy { classDef.directMethods.map { directMethod -> directMethod.toMutable() }.toMutableSet() }
|
||||||
private val virtualMethods =
|
private val _virtualMethods by lazy { classDef.virtualMethods.map { virtualMethod -> virtualMethod.toMutable() }.toMutableSet() }
|
||||||
classDef.virtualMethods.map { virtualMethod -> virtualMethod.toMutable() }.toMutableSet()
|
|
||||||
|
|
||||||
// Fields
|
// Fields
|
||||||
private val fields = classDef.fields.map { field -> field.toMutable() }.toMutableSet()
|
private val _fields by lazy { classDef.fields.map { field -> field.toMutable() }.toMutableSet() }
|
||||||
private val staticFields = classDef.staticFields.map { staticField -> staticField.toMutable() }.toMutableSet()
|
private val _staticFields by lazy { classDef.staticFields.map { staticField -> staticField.toMutable() }.toMutableSet() }
|
||||||
private val instanceFields =
|
private val _instanceFields by lazy { classDef.instanceFields.map { instanceFields -> instanceFields.toMutable() }.toMutableSet() }
|
||||||
classDef.instanceFields.map { instanceFields -> instanceFields.toMutable() }.toMutableSet()
|
|
||||||
|
|
||||||
fun setType(type: String) {
|
fun setType(type: String) {
|
||||||
this.type = type
|
this.type = type
|
||||||
@ -61,34 +59,34 @@ class MutableClass(classDef: ClassDef) : ClassDef, BaseTypeReference() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getInterfaces(): MutableList<String> {
|
override fun getInterfaces(): MutableList<String> {
|
||||||
return interfaces
|
return _interfaces
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
||||||
return annotations
|
return _annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getStaticFields(): MutableSet<MutableField> {
|
override fun getStaticFields(): MutableSet<MutableField> {
|
||||||
return staticFields
|
return _staticFields
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getInstanceFields(): MutableSet<MutableField> {
|
override fun getInstanceFields(): MutableSet<MutableField> {
|
||||||
return instanceFields
|
return _instanceFields
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getFields(): MutableSet<MutableField> {
|
override fun getFields(): MutableSet<MutableField> {
|
||||||
return fields
|
return _fields
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getDirectMethods(): MutableSet<MutableMethod> {
|
override fun getDirectMethods(): MutableSet<MutableMethod> {
|
||||||
return directMethods
|
return _directMethods
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getVirtualMethods(): MutableSet<MutableMethod> {
|
override fun getVirtualMethods(): MutableSet<MutableMethod> {
|
||||||
return virtualMethods
|
return _virtualMethods
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getMethods(): MutableSet<MutableMethod> {
|
override fun getMethods(): MutableSet<MutableMethod> {
|
||||||
return methods
|
return _methods
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -11,7 +11,6 @@ class MutableEncodedValue(encodedValue: EncodedValue) : EncodedValue {
|
|||||||
|
|
||||||
override fun compareTo(other: EncodedValue): Int {
|
override fun compareTo(other: EncodedValue): Int {
|
||||||
return valueType - other.valueType
|
return valueType - other.valueType
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getValueType(): Int {
|
override fun getValueType(): Int {
|
||||||
|
@ -11,10 +11,10 @@ class MutableField(field: Field) : Field, BaseFieldReference() {
|
|||||||
private var type = field.type
|
private var type = field.type
|
||||||
private var accessFlags = field.accessFlags
|
private var accessFlags = field.accessFlags
|
||||||
private var initialValue = field.initialValue?.toMutable()
|
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) {
|
fun setDefiningClass(definingClass: String) {
|
||||||
this.definingClass
|
this.definingClass = definingClass
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setName(name: String) {
|
fun setName(name: String) {
|
||||||
@ -46,7 +46,7 @@ class MutableField(field: Field) : Field, BaseFieldReference() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
||||||
return this.annotations
|
return this._annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAccessFlags(): Int {
|
override fun getAccessFlags(): Int {
|
||||||
|
@ -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)
|
// Create own mutable MethodImplementation (due to not being able to change members like register count)
|
||||||
private var implementation = method.implementation?.let { MutableMethodImplementation(it) }
|
private var implementation = method.implementation?.let { MutableMethodImplementation(it) }
|
||||||
private val annotations = method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet()
|
private val _annotations by lazy { method.annotations.map { annotation -> annotation.toMutable() }.toMutableSet() }
|
||||||
private val parameters = method.parameters.map { parameter -> parameter.toMutable() }.toMutableList()
|
private val _parameters by lazy { method.parameters.map { parameter -> parameter.toMutable() }.toMutableList() }
|
||||||
private val parameterTypes = method.parameterTypes.toMutableList()
|
private val _parameterTypes by lazy { method.parameterTypes.toMutableList() }
|
||||||
|
|
||||||
override fun getDefiningClass(): String {
|
override fun getDefiningClass(): String {
|
||||||
return this.definingClass
|
return this.definingClass
|
||||||
@ -27,7 +27,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getParameterTypes(): MutableList<CharSequence> {
|
override fun getParameterTypes(): MutableList<CharSequence> {
|
||||||
return parameterTypes
|
return _parameterTypes
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getReturnType(): String {
|
override fun getReturnType(): String {
|
||||||
@ -35,7 +35,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
||||||
return annotations
|
return _annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getAccessFlags(): Int {
|
override fun getAccessFlags(): Int {
|
||||||
@ -43,7 +43,7 @@ class MutableMethod(method: Method) : Method, BaseMethodReference() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getParameters(): MutableList<MutableMethodParameter> {
|
override fun getParameters(): MutableList<MutableMethodParameter> {
|
||||||
return parameters
|
return _parameters
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getImplementation(): MutableMethodImplementation? {
|
override fun getImplementation(): MutableMethodImplementation? {
|
||||||
|
@ -9,7 +9,7 @@ class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, Base
|
|||||||
private var type = parameter.type
|
private var type = parameter.type
|
||||||
private var name = parameter.name
|
private var name = parameter.name
|
||||||
private var signature = parameter.signature
|
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 {
|
override fun getType(): String {
|
||||||
return type
|
return type
|
||||||
@ -24,7 +24,7 @@ class MutableMethodParameter(parameter: MethodParameter) : MethodParameter, Base
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
override fun getAnnotations(): MutableSet<MutableAnnotation> {
|
||||||
return annotations
|
return _annotations
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user