From 25b8243f8f73e6c75457287f7e3810061228c163 Mon Sep 17 00:00:00 2001 From: xarkes Date: Wed, 16 Jan 2019 12:50:27 +0100 Subject: [PATCH] Improved xref widget performances (#1112) * Improved xref widget performances Removed call to afij that could be very slow. * Deleted destructor definition It is bydefault defined in QObject derived classes so since it's empty we should better ommit it * Use pd-- and readd destructor --- src/dialogs/XrefsDialog.cpp | 67 ++++++++++++++----------------------- src/dialogs/XrefsDialog.h | 1 - 2 files changed, 26 insertions(+), 42 deletions(-) diff --git a/src/dialogs/XrefsDialog.cpp b/src/dialogs/XrefsDialog.cpp index 4c8ba90a..989aed76 100644 --- a/src/dialogs/XrefsDialog.cpp +++ b/src/dialogs/XrefsDialog.cpp @@ -12,8 +12,7 @@ XrefsDialog::XrefsDialog(QWidget *parent) : QDialog(parent), addr(0), func_name(QString::null), - ui(new Ui::XrefsDialog), - core(Core()) + ui(new Ui::XrefsDialog) { ui->setupUi(this); setWindowFlags(windowFlags() & (~Qt::WindowContextHelpButtonHint)); @@ -30,42 +29,39 @@ XrefsDialog::XrefsDialog(QWidget *parent) : // Highlight current line connect(ui->previewTextEdit, SIGNAL(cursorPositionChanged()), this, SLOT(highlightCurrentLine())); - connect(Config(), SIGNAL(fontsUpdated()), this, SLOT(setupPreviewFont())); connect(Config(), SIGNAL(colorsUpdated()), this, SLOT(setupPreviewColors())); } -XrefsDialog::~XrefsDialog() {} +XrefsDialog::~XrefsDialog() { } void XrefsDialog::fillRefs(QList refs, QList xrefs) { - /* Fill refs */ + // Fill refs ui->fromTreeWidget->clear(); - for (int i = 0; i < refs.size(); ++i) { - XrefDescription xref = refs[i]; - - QTreeWidgetItem *tempItem = new QTreeWidgetItem(); + for (const auto &xref : refs) { + auto *tempItem = new QTreeWidgetItem(); tempItem->setText(0, xref.to_str); - tempItem->setText(1, core->disassembleSingleInstruction(xref.to)); + tempItem->setText(1, Core()->disassembleSingleInstruction(xref.to)); tempItem->setText(2, xrefTypeString(xref.type)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); ui->fromTreeWidget->insertTopLevelItem(0, tempItem); } + // Adjust columns to content qhelpers::adjustColumns(ui->fromTreeWidget, 0); - /* Fill Xrefs */ + // Fill Xrefs ui->toTreeWidget->clear(); - for (int i = 0; i < xrefs.size(); ++i) { - XrefDescription xref = xrefs[i]; - - QTreeWidgetItem *tempItem = new QTreeWidgetItem(); + for (const auto &xref : xrefs) { + auto *tempItem = new QTreeWidgetItem(); tempItem->setText(0, xref.from_str); - tempItem->setText(1, core->disassembleSingleInstruction(xref.from)); + tempItem->setText(1, Core()->disassembleSingleInstruction(xref.from)); tempItem->setText(2, xrefTypeString(xref.type)); tempItem->setData(0, Qt::UserRole, QVariant::fromValue(xref)); ui->toTreeWidget->insertTopLevelItem(0, tempItem); } + // Adjust columns to content qhelpers::adjustColumns(ui->toTreeWidget, 0); } @@ -120,7 +116,7 @@ void XrefsDialog::highlightCurrentLine() QList extraSelections; if (ui->previewTextEdit->isReadOnly()) { - QTextEdit::ExtraSelection selection; + QTextEdit::ExtraSelection selection = QTextEdit::ExtraSelection(); selection.format.setBackground(ConfigColor("highlight")); selection.format.setProperty(QTextFormat::FullWidthSelection, true); @@ -134,8 +130,9 @@ void XrefsDialog::highlightCurrentLine() void XrefsDialog::on_fromTreeWidget_itemSelectionChanged() { - if (ui->fromTreeWidget->selectedItems().isEmpty()) + if (ui->fromTreeWidget->selectedItems().isEmpty()) { return; + } ui->toTreeWidget->clearSelection(); QTreeWidgetItem *item = ui->fromTreeWidget->currentItem(); XrefDescription xref = item->data(0, Qt::UserRole).value(); @@ -144,8 +141,9 @@ void XrefsDialog::on_fromTreeWidget_itemSelectionChanged() void XrefsDialog::on_toTreeWidget_itemSelectionChanged() { - if (ui->toTreeWidget->selectedItems().isEmpty()) + if (ui->toTreeWidget->selectedItems().isEmpty()) { return; + } ui->fromTreeWidget->clearSelection(); QTreeWidgetItem *item = ui->toTreeWidget->currentItem(); XrefDescription xref = item->data(0, Qt::UserRole).value(); @@ -154,25 +152,15 @@ void XrefsDialog::on_toTreeWidget_itemSelectionChanged() void XrefsDialog::updatePreview(RVA addr) { - // is the address part of a function, so we can use pdf? - bool isFunction = !core->cmdj("afij@" + QString::number(addr)).array().isEmpty(); - TempConfig tempConfig; tempConfig.set("scr.html", true); tempConfig.set("scr.color", COLOR_MODE_16M); - QString disass; - - if (isFunction) - disass = core->cmd("pdf @ " + QString::number(addr)); - else - disass = core->cmd("pd 10 @ " + QString::number(addr)); - - ui->previewTextEdit->document()->setHtml(disass); + QString disas = Core()->cmd("pd--20 @ " + QString::number(addr)); + ui->previewTextEdit->document()->setHtml(disas); // Does it make any sense? - ui->previewTextEdit->moveCursor(QTextCursor::End); - ui->previewTextEdit->find(this->normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward); + ui->previewTextEdit->find(normalizeAddr(RAddressString(addr)), QTextDocument::FindBackward); ui->previewTextEdit->moveCursor(QTextCursor::StartOfLine, QTextCursor::MoveAnchor); } @@ -188,18 +176,12 @@ void XrefsDialog::fillRefsForAddress(RVA addr, QString name, bool whole_function tempConfig.set("scr.html", false); tempConfig.set("scr.color", COLOR_MODE_DISABLED); - this->addr = addr; - this->func_name = func_name; - setWindowTitle(tr("X-Refs for %1").arg(name)); updateLabels(name); + // Get Refs and Xrefs - - // refs = calls q hace esa funcion - QList refs = core->getXRefs(addr, false, whole_function); - - // xrefs = calls a esa funcion - QList xrefs = core->getXRefs(addr, true, whole_function); + QList refs = Core()->getXRefs(addr, false, whole_function); + QList xrefs = Core()->getXRefs(addr, true, whole_function); fillRefs(refs, xrefs); } @@ -217,6 +199,9 @@ QString XrefsDialog::xrefTypeString(const QString &type) return QString(""); case R_ANAL_REF_TYPE_STRING: return QString("String"); + default: + break; } return type; } + diff --git a/src/dialogs/XrefsDialog.h b/src/dialogs/XrefsDialog.h index c5579379..6aa0708d 100644 --- a/src/dialogs/XrefsDialog.h +++ b/src/dialogs/XrefsDialog.h @@ -42,7 +42,6 @@ private: QString func_name; std::unique_ptr ui; - CutterCore *core; void fillRefs(QList refs, QList xrefs); void updateLabels(QString name);