Speed up method param renaming code
This commit is contained in:
parent
96c13fb05e
commit
50e7d28ddf
|
@ -29,7 +29,7 @@ namespace de4dot.code.renamer {
|
||||||
class TypeInfo : MemberInfo {
|
class TypeInfo : MemberInfo {
|
||||||
public string oldNamespace;
|
public string oldNamespace;
|
||||||
public string newNamespace;
|
public string newNamespace;
|
||||||
public VariableNameState variableNameState = new VariableNameState();
|
public VariableNameState variableNameState = VariableNameState.create();
|
||||||
public TypeDef type;
|
public TypeDef type;
|
||||||
MemberInfos memberInfos;
|
MemberInfos memberInfos;
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ namespace de4dot.code.renamer {
|
||||||
info.newName = "e";
|
info.newName = "e";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var newVariableNameState = variableNameState.clone();
|
var newVariableNameState = variableNameState.cloneParamsOnly();
|
||||||
var checker = NameChecker;
|
var checker = NameChecker;
|
||||||
foreach (var paramDef in methodDef.ParamDefs) {
|
foreach (var paramDef in methodDef.ParamDefs) {
|
||||||
var info = param(paramDef);
|
var info = param(paramDef);
|
||||||
|
|
|
@ -96,7 +96,9 @@ namespace de4dot.code.renamer {
|
||||||
}
|
}
|
||||||
|
|
||||||
class VariableNameCreator : TypeNames {
|
class VariableNameCreator : TypeNames {
|
||||||
public VariableNameCreator() {
|
public VariableNameCreator(bool init = true) {
|
||||||
|
if (!init)
|
||||||
|
return;
|
||||||
initTypeName("System.Boolean", "bool");
|
initTypeName("System.Boolean", "bool");
|
||||||
initTypeName("System.Byte", "byte");
|
initTypeName("System.Byte", "byte");
|
||||||
initTypeName("System.Char", "char");
|
initTypeName("System.Char", "char");
|
||||||
|
|
|
@ -21,19 +21,43 @@ using Mono.Cecil;
|
||||||
|
|
||||||
namespace de4dot.code.renamer {
|
namespace de4dot.code.renamer {
|
||||||
class VariableNameState {
|
class VariableNameState {
|
||||||
ExistingNames existingVariableNames = new ExistingNames();
|
ExistingNames existingVariableNames;
|
||||||
ExistingNames existingMethodNames = new ExistingNames();
|
ExistingNames existingMethodNames;
|
||||||
ExistingNames existingPropertyNames = new ExistingNames();
|
ExistingNames existingPropertyNames;
|
||||||
ExistingNames existingEventNames = new ExistingNames();
|
ExistingNames existingEventNames;
|
||||||
TypeNames variableNameCreator = new VariableNameCreator(); // For fields and method args
|
TypeNames variableNameCreator; // For fields and method args
|
||||||
TypeNames propertyNameCreator = new PropertyNameCreator();
|
TypeNames propertyNameCreator;
|
||||||
NameCreator eventNameCreator = new NameCreator("Event_");
|
NameCreator eventNameCreator;
|
||||||
NameCreator genericPropertyNameCreator = new NameCreator("Prop_");
|
NameCreator genericPropertyNameCreator;
|
||||||
public NameCreator staticMethodNameCreator = new NameCreator("smethod_");
|
public NameCreator staticMethodNameCreator;
|
||||||
public NameCreator instanceMethodNameCreator = new NameCreator("method_");
|
public NameCreator instanceMethodNameCreator;
|
||||||
|
|
||||||
public VariableNameState clone() {
|
public static VariableNameState create() {
|
||||||
return new VariableNameState().merge(this);
|
var vns = new VariableNameState();
|
||||||
|
vns.existingVariableNames = new ExistingNames();
|
||||||
|
vns.existingMethodNames = new ExistingNames();
|
||||||
|
vns.existingPropertyNames = new ExistingNames();
|
||||||
|
vns.existingEventNames = new ExistingNames();
|
||||||
|
vns.variableNameCreator = new VariableNameCreator();
|
||||||
|
vns.propertyNameCreator = new PropertyNameCreator();
|
||||||
|
vns.eventNameCreator = new NameCreator("Event_");
|
||||||
|
vns.genericPropertyNameCreator = new NameCreator("Prop_");
|
||||||
|
vns.staticMethodNameCreator = new NameCreator("smethod_");
|
||||||
|
vns.instanceMethodNameCreator = new NameCreator("method_");
|
||||||
|
return vns;
|
||||||
|
}
|
||||||
|
|
||||||
|
VariableNameState() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Cloning only params will speed up the method param renaming code
|
||||||
|
public VariableNameState cloneParamsOnly() {
|
||||||
|
var vns = new VariableNameState();
|
||||||
|
vns.existingVariableNames = new ExistingNames();
|
||||||
|
vns.variableNameCreator = new VariableNameCreator(false);
|
||||||
|
vns.existingVariableNames.merge(existingVariableNames);
|
||||||
|
vns.variableNameCreator.merge(variableNameCreator);
|
||||||
|
return vns;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VariableNameState merge(VariableNameState other) {
|
public VariableNameState merge(VariableNameState other) {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user