From 01617ae6842c1fd92d4bdd63cceeb674ddb22292 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 31 Jul 2025 20:03:26 +0200 Subject: [PATCH] Optimize Debug Commands name building and support nested classes with name hierarchy --- Source/Engine/Debug/DebugCommands.cpp | 37 ++++++++++++++++++++++----- 1 file changed, 31 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Debug/DebugCommands.cpp b/Source/Engine/Debug/DebugCommands.cpp index 6927a1da9..45bd202c3 100644 --- a/Source/Engine/Debug/DebugCommands.cpp +++ b/Source/Engine/Debug/DebugCommands.cpp @@ -186,6 +186,34 @@ namespace Task* AsyncTask = nullptr; Array Commands; + void BuildName(CommandData& cmd, const MClass* mclass, const StringAnsiView& itemName) + { + StringAnsiView mclassName = mclass->GetName(); + StringAnsiView mclassFullname = mclass->GetFullName(); + StringAnsiView mclassNamespace = mclass->GetNamespace(); + + Array> 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) { if (module == GetBinaryModuleCorlib()) @@ -206,8 +234,6 @@ namespace mclass->IsEnum()) continue; 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 const auto& methods = mclass->GetMethods(); @@ -231,7 +257,7 @@ namespace continue; auto& commandData = Commands.AddOne(); - BUILD_NAME(commandData, method->GetName()); + BuildName(commandData, mclass, method->GetName()); commandData.Module = module; commandData.Method = method; } @@ -248,7 +274,7 @@ namespace continue; auto& commandData = Commands.AddOne(); - BUILD_NAME(commandData, field->GetName()); + BuildName(commandData, mclass, field->GetName()); commandData.Module = module; commandData.Field = field; } @@ -265,13 +291,12 @@ namespace continue; auto& commandData = Commands.AddOne(); - BUILD_NAME(commandData, property->GetName()); + BuildName(commandData, mclass, property->GetName()); commandData.Module = module; commandData.MethodGet = property->GetGetMethod(); commandData.MethodSet = property->GetSetMethod(); } } -#undef BUILD_NAME } else #endif