Commit aad70c71 authored by Skylot's avatar Skylot

perf: cache types in dex nodes

parent a051ce6c
...@@ -38,12 +38,14 @@ public class DexNode implements IDexNode { ...@@ -38,12 +38,14 @@ public class DexNode implements IDexNode {
private final List<ClassNode> classes = new ArrayList<>(); private final List<ClassNode> classes = new ArrayList<>();
private final Map<ClassInfo, ClassNode> clsMap = new HashMap<>(); private final Map<ClassInfo, ClassNode> clsMap = new HashMap<>();
private final ArgType[] typesCache;
public DexNode(RootNode root, DexFile input, int dexId) { public DexNode(RootNode root, DexFile input, int dexId) {
this.root = root; this.root = root;
this.file = input; this.file = input;
this.dexBuf = input.getDexBuf(); this.dexBuf = input.getDexBuf();
this.dexId = dexId; this.dexId = dexId;
this.typesCache = new ArgType[dexBuf.typeIds().size()];
} }
public void loadClasses() { public void loadClasses() {
...@@ -207,7 +209,15 @@ public class DexNode implements IDexNode { ...@@ -207,7 +209,15 @@ public class DexNode implements IDexNode {
if (index == DexNode.NO_INDEX) { if (index == DexNode.NO_INDEX) {
return null; return null;
} }
return ArgType.parse(getString(dexBuf.typeIds().get(index))); ArgType type = typesCache[index];
if (type != null) {
return type;
}
// no synchronization because exactly one ArgType instance not needed, just reduce instances count
// note: same types but different instances will exist in other dex nodes
ArgType parsedType = ArgType.parse(getString(dexBuf.typeIds().get(index)));
typesCache[index] = parsedType;
return parsedType;
} }
public MethodId getMethodId(int mthIndex) { public MethodId getMethodId(int mthIndex) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment