Skip to content

Commit 40e3614

Browse files
committed
[DEX] Overhaul, minimise new runtime object creation
1 parent 169fe39 commit 40e3614

47 files changed

Lines changed: 1376 additions & 492 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/com/reandroid/dex/common/IdUsageIterator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ default Iterator<Key> usedKeys(){
3030
@SuppressWarnings("unchecked")
3131
@Override
3232
public Iterator<Key> iterator(IdItem element) {
33-
return (Iterator<Key>) element.getKey().mentionedKeys();
33+
return (Iterator<Key>) element.getKey().contents();
3434
}
3535
};
3636
}

src/main/java/com/reandroid/dex/common/SectionItem.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.reandroid.dex.key.Key;
77
import com.reandroid.dex.sections.SectionList;
88
import com.reandroid.dex.sections.SectionType;
9+
import com.reandroid.utils.ObjectsUtil;
910

1011
public class SectionItem extends BlockItem implements EditableItem, SectionTool, UsageMarker {
1112

@@ -66,15 +67,17 @@ public boolean isRemoved(){
6667
public void onRemovedInternal() {
6768
}
6869

69-
@SuppressWarnings("unchecked")
7070
protected <T1 extends Key> T1 checkKey(T1 newKey){
71-
Key lastKey = this.mLastKey;
71+
T1 lastKey = getLastKey();
7272
if(lastKey == null || !lastKey.equals(newKey)){
7373
this.mLastKey = newKey;
7474
keyChanged(lastKey);
7575
lastKey = newKey;
7676
}
77-
return (T1) lastKey;
77+
return lastKey;
78+
}
79+
protected <T1 extends Key> T1 getLastKey() {
80+
return ObjectsUtil.cast(mLastKey);
7881
}
7982
protected void keyChanged(Key oldKey){
8083
if(oldKey == null){
@@ -126,29 +129,6 @@ public void editInternal(Block user) {
126129
public void removeSelf(){
127130
throw new RuntimeException("Not implemented");
128131
}
129-
public boolean equalsKey(SectionItem sectionItem){
130-
if(sectionItem == this){
131-
return true;
132-
}
133-
if(sectionItem == null || getSectionType() != sectionItem.getSectionType()){
134-
return false;
135-
}
136-
Key key = getKey();
137-
if(key == null){
138-
return false;
139-
}
140-
return key.equals(sectionItem.getKey());
141-
}
142-
public boolean equalsKey(Key key){
143-
if(key == null){
144-
return false;
145-
}
146-
Key myKey = getKey();
147-
if(myKey == null){
148-
return false;
149-
}
150-
return myKey.equals(key);
151-
}
152132
public boolean isBlank() {
153133
return isRemoved();
154134
}

src/main/java/com/reandroid/dex/dalvik/DalvikEnclosingClass.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@
1616
package com.reandroid.dex.dalvik;
1717

1818
import com.reandroid.dex.common.AnnotationVisibility;
19-
import com.reandroid.dex.key.*;
19+
import com.reandroid.dex.key.AnnotationElementKey;
20+
import com.reandroid.dex.key.AnnotationItemKey;
21+
import com.reandroid.dex.key.Key;
22+
import com.reandroid.dex.key.NullValueKey;
23+
import com.reandroid.dex.key.TypeKey;
2024
import com.reandroid.dex.program.AnnotatedProgram;
2125
import com.reandroid.dex.program.ClassProgram;
2226

@@ -34,10 +38,11 @@ public static DalvikEnclosingClass of(AnnotatedProgram annotatedProgram) {
3438
}
3539
public static DalvikEnclosingClass getOrCreate(AnnotatedProgram annotatedProgram) {
3640
if (!annotatedProgram.hasAnnotation(TypeKey.DALVIK_EnclosingClass)) {
37-
Key key;
41+
Key key = null;
3842
if (annotatedProgram instanceof ClassProgram) {
39-
key = ((ClassProgram) annotatedProgram).getKey();
40-
} else {
43+
key = ((ClassProgram) annotatedProgram).getKey().getEnclosingClass();
44+
}
45+
if (key == null) {
4146
key = NullValueKey.INSTANCE;
4247
}
4348
annotatedProgram.addAnnotation(AnnotationItemKey.create(

src/main/java/com/reandroid/dex/dalvik/DalvikInnerClass.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.reandroid.dex.key.TypeKey;
2727
import com.reandroid.dex.program.AccessibleItem;
2828
import com.reandroid.dex.program.AnnotatedProgram;
29+
import com.reandroid.dex.program.ClassProgram;
2930

3031
import java.lang.annotation.ElementType;
3132

@@ -81,11 +82,21 @@ public static DalvikInnerClass of(AnnotatedProgram annotatedProgram) {
8182
}
8283
public static DalvikInnerClass getOrCreate(AnnotatedProgram annotatedProgram) {
8384
if (!annotatedProgram.hasAnnotation(TypeKey.DALVIK_InnerClass)) {
85+
Key name = null;
86+
int accessFlags = 0;
87+
if (annotatedProgram instanceof ClassProgram) {
88+
ClassProgram classProgram = (ClassProgram) annotatedProgram;
89+
name = StringKey.create(classProgram.getKey().getSimpleInnerName());
90+
accessFlags = classProgram.getAccessFlagsValue();
91+
}
92+
if (name == null) {
93+
name = NullValueKey.INSTANCE;
94+
}
8495
annotatedProgram.addAnnotation(AnnotationItemKey.create(
8596
AnnotationVisibility.SYSTEM,
8697
TypeKey.DALVIK_InnerClass,
87-
AnnotationElementKey.create(Key.DALVIK_accessFlags, PrimitiveKey.of(0)),
88-
AnnotationElementKey.create(Key.DALVIK_name, NullValueKey.INSTANCE)
98+
AnnotationElementKey.create(Key.DALVIK_accessFlags, PrimitiveKey.of(accessFlags)),
99+
AnnotationElementKey.create(Key.DALVIK_name, name)
89100
)
90101
);
91102
}

src/main/java/com/reandroid/dex/dalvik/DalvikSignature.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,4 +84,11 @@ public static DalvikSignature getOrCreate(AnnotatedProgram annotatedProgram) {
8484
}
8585
return of(annotatedProgram);
8686
}
87+
public static DalvikSignatureKey getSignature(AnnotatedProgram annotatedProgram) {
88+
DalvikSignature dalvikSignature = DalvikSignature.of(annotatedProgram);
89+
if (dalvikSignature != null) {
90+
return dalvikSignature.getSignature();
91+
}
92+
return null;
93+
}
8794
}

0 commit comments

Comments
 (0)