提交 b46093b3 编写于 作者: S Skylot

core: add method info cache

上级 2b9c0927
......@@ -132,10 +132,7 @@ public final class MethodInfo {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
if (!(obj instanceof MethodInfo)) {
return false;
}
MethodInfo other = (MethodInfo) obj;
......
......@@ -25,6 +25,7 @@ import jadx.core.utils.exceptions.JadxRuntimeException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
......@@ -65,6 +66,9 @@ public class ClassNode extends LineAttrNode implements ILoadable {
private ProcessState state = ProcessState.NOT_LOADED;
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 {
this.dex = dex;
this.clsInfo = ClassInfo.fromDex(dex, cls.getTypeIndex());
......@@ -126,6 +130,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
}
this.accessFlags = new AccessInfo(accFlagsValue, AFType.CLASS);
buildCache();
} catch (Exception e) {
throw new DecodeException("Error decode class: " + clsInfo, e);
}
......@@ -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
public ArgType getSuperClass() {
return superClass;
......@@ -384,12 +396,7 @@ public class ClassNode extends LineAttrNode implements ILoadable {
}
public MethodNode searchMethod(MethodInfo mth) {
for (MethodNode m : methods) {
if (m.getMethodInfo().equals(mth)) {
return m;
}
}
return null;
return mthInfoMap.get(mth);
}
public MethodNode searchMethodByName(String shortId) {
......
......@@ -513,11 +513,11 @@ public class MethodNode extends LineAttrNode implements ILoadable {
}
String name = getName();
List<MethodNode> methods = parentClass.getMethods();
for (MethodNode method : methods) {
for (MethodNode method : parentClass.getMethods()) {
MethodInfo otherMthInfo = method.mthInfo;
if (this != method
&& method.getName().equals(name)
&& method.mthInfo.getArgumentsTypes().size() == argsCount) {
&& otherMthInfo.getArgumentsTypes().size() == argsCount
&& otherMthInfo.getName().equals(name)) {
return true;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册