Optimize Debug Commands name building and support nested classes with name hierarchy
This commit is contained in:
@@ -186,6 +186,34 @@ namespace
|
|||||||
Task* AsyncTask = nullptr;
|
Task* AsyncTask = nullptr;
|
||||||
Array<CommandData> Commands;
|
Array<CommandData> Commands;
|
||||||
|
|
||||||
|
void BuildName(CommandData& cmd, const MClass* mclass, const StringAnsiView& itemName)
|
||||||
|
{
|
||||||
|
StringAnsiView mclassName = mclass->GetName();
|
||||||
|
StringAnsiView mclassFullname = mclass->GetFullName();
|
||||||
|
StringAnsiView mclassNamespace = mclass->GetNamespace();
|
||||||
|
|
||||||
|
Array<Char, InlinedAllocation<200>> buffer; // Stack-based but with option to alloc in case of very long commands
|
||||||
|
buffer.Resize(mclassFullname.Length() - mclassNamespace.Length() + itemName.Length() + 1);
|
||||||
|
Char* bufferPtr = buffer.Get();
|
||||||
|
|
||||||
|
// Check if class is nested, then include outer class name for hierarchy
|
||||||
|
if (mclassNamespace.Length() + mclassName.Length() + 1 != mclassFullname.Length())
|
||||||
|
{
|
||||||
|
StringAnsiView outerName(mclassFullname.Get() + mclassNamespace.Length() + 1, mclassFullname.Length() - mclassNamespace.Length() - 2 - mclassName.Length());
|
||||||
|
StringUtils::Copy(bufferPtr, outerName.Get(), outerName.Length());
|
||||||
|
bufferPtr += outerName.Length();
|
||||||
|
*bufferPtr++ = '.';
|
||||||
|
}
|
||||||
|
StringUtils::Copy(bufferPtr, mclassName.Get(), mclassName.Length());
|
||||||
|
bufferPtr += mclassName.Length();
|
||||||
|
*bufferPtr++ = '.';
|
||||||
|
StringUtils::Copy(bufferPtr, itemName.Get(), itemName.Length());
|
||||||
|
bufferPtr += itemName.Length();
|
||||||
|
*bufferPtr++ = 0;
|
||||||
|
|
||||||
|
cmd.Name.Set(buffer.Get(), (int32)(bufferPtr - buffer.Get()));
|
||||||
|
}
|
||||||
|
|
||||||
void FindDebugCommands(BinaryModule* module)
|
void FindDebugCommands(BinaryModule* module)
|
||||||
{
|
{
|
||||||
if (module == GetBinaryModuleCorlib())
|
if (module == GetBinaryModuleCorlib())
|
||||||
@@ -206,8 +234,6 @@ namespace
|
|||||||
mclass->IsEnum())
|
mclass->IsEnum())
|
||||||
continue;
|
continue;
|
||||||
const bool useClass = mclass->HasAttribute(attribute);
|
const bool useClass = mclass->HasAttribute(attribute);
|
||||||
// TODO: optimize this via stack-based format buffer and then convert Ansi to UTF16
|
|
||||||
#define BUILD_NAME(commandData, itemName) commandData.Name = String(mclass->GetName()) + TEXT(".") + String(itemName)
|
|
||||||
|
|
||||||
// Process methods
|
// Process methods
|
||||||
const auto& methods = mclass->GetMethods();
|
const auto& methods = mclass->GetMethods();
|
||||||
@@ -231,7 +257,7 @@ namespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto& commandData = Commands.AddOne();
|
auto& commandData = Commands.AddOne();
|
||||||
BUILD_NAME(commandData, method->GetName());
|
BuildName(commandData, mclass, method->GetName());
|
||||||
commandData.Module = module;
|
commandData.Module = module;
|
||||||
commandData.Method = method;
|
commandData.Method = method;
|
||||||
}
|
}
|
||||||
@@ -248,7 +274,7 @@ namespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto& commandData = Commands.AddOne();
|
auto& commandData = Commands.AddOne();
|
||||||
BUILD_NAME(commandData, field->GetName());
|
BuildName(commandData, mclass, field->GetName());
|
||||||
commandData.Module = module;
|
commandData.Module = module;
|
||||||
commandData.Field = field;
|
commandData.Field = field;
|
||||||
}
|
}
|
||||||
@@ -265,13 +291,12 @@ namespace
|
|||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto& commandData = Commands.AddOne();
|
auto& commandData = Commands.AddOne();
|
||||||
BUILD_NAME(commandData, property->GetName());
|
BuildName(commandData, mclass, property->GetName());
|
||||||
commandData.Module = module;
|
commandData.Module = module;
|
||||||
commandData.MethodGet = property->GetGetMethod();
|
commandData.MethodGet = property->GetGetMethod();
|
||||||
commandData.MethodSet = property->GetSetMethod();
|
commandData.MethodSet = property->GetSetMethod();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef BUILD_NAME
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user