Changes to TagsView to improve performance.

This commit is contained in:
Jean-Philip Desjardins 2023-11-29 16:00:54 -05:00
parent 207d840329
commit 9b7f7fca42
6 changed files with 51 additions and 66 deletions

View file

@ -372,9 +372,9 @@ void CMIPSAnalysis::AnalyseStringReferences()
std::string stringConstant;
if(TryGetStringAtAddress(m_ctx, targetAddress, stringConstant))
{
if(m_ctx->m_Comments.Find(address) == nullptr)
if(!m_ctx->m_Comments.Find(address))
{
m_ctx->m_Comments.InsertTag(address, stringConstant.c_str());
m_ctx->m_Comments.InsertTag(address, std::move(stringConstant));
commentInserted = true;
}
}

View file

@ -1,37 +1,22 @@
#include <cstring>
#include "MIPSTags.h"
#include "StdStream.h"
#include "lexical_cast_ex.h"
#include "string_format.h"
#include "xml/FilteringNodeIterator.h"
#define TAG_ELEMENT_NAME ("tag")
#define TAG_ELEMENT_ATTRIBUTE_ADDRESS ("address")
#define TAG_ELEMENT_ATTRIBUTE_VALUE ("value")
void CMIPSTags::InsertTag(uint32 nAddress, const char* sTag)
void CMIPSTags::InsertTag(uint32 address, std::string tag)
{
bool nErase = false;
if(sTag == nullptr)
{
nErase = true;
}
else
{
nErase = (strlen(sTag) == 0);
}
assert(!tag.empty());
m_tags[address] = std::move(tag);
}
if(nErase)
{
auto tagIterator = m_tags.find(nAddress);
if(tagIterator != m_tags.end())
{
m_tags.erase(tagIterator);
}
}
else
{
m_tags[nAddress] = sTag;
}
void CMIPSTags::RemoveTag(uint32 address)
{
m_tags.erase(address);
}
void CMIPSTags::RemoveTags()
@ -109,7 +94,7 @@ void CMIPSTags::Serialize(Framework::Xml::CNode* parentNode) const
for(const auto& tagPair : m_tags)
{
auto node = std::make_unique<Framework::Xml::CNode>(TAG_ELEMENT_NAME, true);
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS, lexical_cast_hex<std::string>(tagPair.first, 8).c_str());
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS, string_format("%08X", tagPair.first).c_str());
node->InsertAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE, tagPair.second.c_str());
parentNode->InsertNode(std::move(node));
}
@ -124,7 +109,7 @@ void CMIPSTags::Unserialize(Framework::Xml::CNode* parentNode)
auto addressText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_ADDRESS);
auto valueText = node->GetAttribute(TAG_ELEMENT_ATTRIBUTE_VALUE);
if(!addressText || !valueText) continue;
uint32 address = lexical_cast_hex<std::string>(addressText);
uint32 address = strtoul(addressText, nullptr, 16);
InsertTag(address, valueText);
}
}

View file

@ -14,7 +14,8 @@ public:
Framework::CSignal<void()> OnTagListChange;
void InsertTag(uint32, const char*);
void InsertTag(uint32, std::string);
void RemoveTag(uint32);
void RemoveTags();
const char* Find(uint32) const;

View file

@ -3923,9 +3923,10 @@ void CIopBios::PrepareModuleDebugInfo(CELF32& elf, const ExecutableRange& module
sprintf(functionNameTemp, "unknown_%04X", functionId);
functionName = functionNameTemp;
}
if(m_cpu.m_Functions.Find(address) == NULL)
if(!m_cpu.m_Functions.Find(address))
{
m_cpu.m_Functions.InsertTag(entryAddress, (std::string(moduleName) + "_" + functionName).c_str());
auto fullFunctionName = std::string(moduleName) + "_" + functionName;
m_cpu.m_Functions.InsertTag(entryAddress, std::move(fullFunctionName));
functionAdded = true;
}
entryAddress += 8;

View file

@ -43,7 +43,8 @@ void CTagsView::Refresh()
void CTagsView::RefreshList()
{
m_groupMap.clear();
m_globalItem.reset();
m_moduleItems.clear();
ui->treeWidget->clear();
if(!m_context) return;
@ -55,34 +56,31 @@ void CTagsView::RefreshList()
{
m_modules.clear();
}
bool groupingEnabled = m_modules.size() != 0;
if(groupingEnabled)
{
InitializeModuleGrouper();
}
InitializeModuleItems();
for(auto itTag(m_tags->GetTagsBegin());
itTag != m_tags->GetTagsEnd(); itTag++)
{
std::string sTag(itTag->second);
const auto& sTag(itTag->second);
if(!m_filter.empty() && (sTag.find(m_filter) == std::string::npos))
{
continue;
}
QTreeWidgetItem* childItem = new QTreeWidgetItem();
childItem->setText(0, sTag.c_str());
childItem->setText(1, string_format("0x%08X", itTag->first).c_str());
childItem->setText(0, QString::fromStdString(sTag));
childItem->setText(1, QString::fromStdString(string_format("0x%08X", itTag->first)));
childItem->setData(addressValueColumn, addressValueRole, itTag->first);
if(groupingEnabled)
{
GetTagGroup(itTag->first)->addChild(childItem);
}
else
{
ui->treeWidget->addTopLevelItem(childItem);
}
auto moduleItem = GetModuleItem(itTag->first);
moduleItem->addChild(childItem);
}
ui->treeWidget->addTopLevelItem(m_globalItem.get());
for(const auto& moduleItemPair : m_moduleItems)
{
ui->treeWidget->addTopLevelItem(moduleItemPair.second.get());
}
if(!m_filter.empty())
@ -91,30 +89,28 @@ void CTagsView::RefreshList()
}
}
void CTagsView::InitializeModuleGrouper()
void CTagsView::InitializeModuleItems()
{
QTreeWidgetItem* rootItem = new QTreeWidgetItem(ui->treeWidget);
rootItem->setText(0, DEFAULT_GROUPNAME);
rootItem->setText(1, "");
ui->treeWidget->addTopLevelItem(rootItem);
m_globalItem = QSharedPointer<QTreeWidgetItem>::create();
m_globalItem->setText(0, DEFAULT_GROUPNAME);
m_globalItem->setText(1, "");
for(const auto& module : m_modules)
{
QTreeWidgetItem* rootItem = new QTreeWidgetItem(ui->treeWidget);
rootItem->setText(0, module.name.c_str());
rootItem->setText(1, string_format("0x%08X -- 0x%08X", module.begin, module.end).c_str());
m_groupMap.emplace(module.begin, rootItem);
ui->treeWidget->addTopLevelItem(rootItem);
auto moduleItem = QSharedPointer<QTreeWidgetItem>::create();
moduleItem->setText(0, module.name.c_str());
moduleItem->setText(1, string_format("0x%08X -- 0x%08X", module.begin, module.end).c_str());
m_moduleItems.emplace(module.begin, std::move(moduleItem));
}
}
QTreeWidgetItem* CTagsView::GetTagGroup(uint32 address)
QTreeWidgetItem* CTagsView::GetModuleItem(uint32 address)
{
for(const auto& module : m_modules)
{
if(address >= module.begin && address < module.end) return m_groupMap[module.begin];
if(address >= module.begin && address < module.end) return m_moduleItems[module.begin].get();
}
return ui->treeWidget->topLevelItem(0);
return m_globalItem.get();
}
void CTagsView::SetStrings(const Strings& strings)
@ -244,7 +240,7 @@ void CTagsView::OnDeleteClick()
for(auto tagIterator = m_tags->GetTagsBegin();
tagIterator != m_tags->GetTagsEnd(); tagIterator++)
{
auto tagGroupItem = GetTagGroup(tagIterator->first);
auto tagGroupItem = GetModuleItem(tagIterator->first);
if(tagGroupItem == selectedItem)
{
toDelete.push_back(tagIterator->first);
@ -253,7 +249,7 @@ void CTagsView::OnDeleteClick()
for(auto address : toDelete)
{
m_tags->InsertTag(address, nullptr);
m_tags->RemoveTag(address);
}
}
else
@ -269,7 +265,7 @@ void CTagsView::OnDeleteClick()
return;
}
m_tags->InsertTag(nAddress, nullptr);
m_tags->RemoveTag(nAddress);
}
RefreshList();

View file

@ -55,8 +55,8 @@ protected:
void showEvent(QShowEvent*) Q_DECL_OVERRIDE;
void RefreshList();
void InitializeModuleGrouper();
QTreeWidgetItem* GetTagGroup(uint32);
void InitializeModuleItems();
QTreeWidgetItem* GetModuleItem(uint32);
Ui::CTagsView* ui;
@ -68,5 +68,7 @@ protected:
CMIPSTags* m_tags = nullptr;
BiosDebugModuleInfoArray m_modules;
CBiosDebugInfoProvider* m_biosDebugInfoProvider = nullptr;
std::map<uint32, QTreeWidgetItem*> m_groupMap;
QSharedPointer<QTreeWidgetItem> m_globalItem;
std::map<uint32, QSharedPointer<QTreeWidgetItem>> m_moduleItems;
};