Commit b46093b3 authored by Skylot's avatar Skylot

core: add method info cache

parent 2b9c0927
...@@ -132,10 +132,7 @@ public final class MethodInfo { ...@@ -132,10 +132,7 @@ public final class MethodInfo {
if (this == obj) { if (this == obj) {
return true; return true;
} }
if (obj == null) { if (!(obj instanceof MethodInfo)) {
return false;
}
if (getClass() != obj.getClass()) {
return false; return false;
} }
MethodInfo other = (MethodInfo) obj; MethodInfo other = (MethodInfo) obj;
......
...@@ -25,6 +25,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException; ...@@ -25,6 +25,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
...@@ -65,6 +66,9 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -65,6 +66,9 @@ public class ClassNode extends LineAttrNode implements ILoadable {
private ProcessState state = ProcessState.NOT_LOADED; private ProcessState state = ProcessState.NOT_LOADED;
private final Set<ClassNode> dependencies = new HashSet<ClassNode>(); private final Set<ClassNode> dependencies = new HashSet<ClassNode>();
// cache maps
private Map<MethodInfo, MethodNode> mthInfoMap = Collections.emptyMap();
public ClassNode(DexNode dex, ClassDef cls) throws DecodeException { public ClassNode(DexNode dex, ClassDef cls) throws DecodeException {
this.dex = dex; this.dex = dex;
this.clsInfo = ClassInfo.fromDex(dex, cls.getTypeIndex()); this.clsInfo = ClassInfo.fromDex(dex, cls.getTypeIndex());
...@@ -126,6 +130,7 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -126,6 +130,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
} }
this.accessFlags = new AccessInfo(accFlagsValue, AFType.CLASS); this.accessFlags = new AccessInfo(accFlagsValue, AFType.CLASS);
buildCache();
} catch (Exception e) { } catch (Exception e) {
throw new DecodeException("Error decode class: " + clsInfo, e); throw new DecodeException("Error decode class: " + clsInfo, e);
} }
...@@ -278,6 +283,13 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -278,6 +283,13 @@ public class ClassNode extends LineAttrNode implements ILoadable {
} }
} }
private void buildCache() {
mthInfoMap = new HashMap<MethodInfo, MethodNode>(methods.size());
for (MethodNode mth : methods) {
mthInfoMap.put(mth.getMethodInfo(), mth);
}
}
@Nullable @Nullable
public ArgType getSuperClass() { public ArgType getSuperClass() {
return superClass; return superClass;
...@@ -384,12 +396,7 @@ public class ClassNode extends LineAttrNode implements ILoadable { ...@@ -384,12 +396,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
} }
public MethodNode searchMethod(MethodInfo mth) { public MethodNode searchMethod(MethodInfo mth) {
for (MethodNode m : methods) { return mthInfoMap.get(mth);
if (m.getMethodInfo().equals(mth)) {
return m;
}
}
return null;
} }
public MethodNode searchMethodByName(String shortId) { public MethodNode searchMethodByName(String shortId) {
......
...@@ -513,11 +513,11 @@ public class MethodNode extends LineAttrNode implements ILoadable { ...@@ -513,11 +513,11 @@ public class MethodNode extends LineAttrNode implements ILoadable {
} }
String name = getName(); String name = getName();
List<MethodNode> methods = parentClass.getMethods(); for (MethodNode method : parentClass.getMethods()) {
for (MethodNode method : methods) { MethodInfo otherMthInfo = method.mthInfo;
if (this != method if (this != method
&& method.getName().equals(name) && otherMthInfo.getArgumentsTypes().size() == argsCount
&& method.mthInfo.getArgumentsTypes().size() == argsCount) { && otherMthInfo.getName().equals(name)) {
return true; return true;
} }
} }
......
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