Optimize VisualNavbar Stats Loading

This commit is contained in:
Florian Märkl 2018-07-06 18:00:26 +02:00
parent b10d132237
commit 125006b1c2
3 changed files with 39 additions and 14 deletions

View File

@ -1537,6 +1537,11 @@ QList<SearchDescription> CutterCore::getAllSearch(QString search_for, QString sp
BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount) BlockStatistics CutterCore::getBlockStatistics(unsigned int blocksCount)
{ {
if (blocksCount == 0) {
BlockStatistics ret;
ret.from = ret.to = ret.blocksize = 0;
return ret;
}
QJsonObject statsObj = cmdj("p-j " + QString::number(blocksCount)).object(); QJsonObject statsObj = cmdj("p-j " + QString::number(blocksCount)).object();
BlockStatistics ret; BlockStatistics ret;

View File

@ -65,32 +65,54 @@ VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) :
setMouseTracking(true); setMouseTracking(true);
} }
unsigned int nextPow2(unsigned int n)
{
unsigned int b = 0;
while (n) {
n >>= 1;
b++;
}
return (1u << b);
}
void VisualNavbar::paintEvent(QPaintEvent *event) void VisualNavbar::paintEvent(QPaintEvent *event)
{ {
Q_UNUSED(event); Q_UNUSED(event);
QPainter painter(this); QPainter painter(this);
if (previousWidth != this->width()) {
auto w = static_cast<unsigned int>(width());
bool fetch = false;
if (statsWidth < w) {
statsWidth = nextPow2(w);
fetch = true;
} else if (statsWidth > w*4) {
statsWidth = statsWidth > 0 ? statsWidth / 2 : 0;
fetch = true;
}
if (fetch) {
fetchAndPaintData(); fetchAndPaintData();
previousWidth = this->width(); } else if (previousWidth != w) {
this->previousWidth = w;
updateGraphicsScene();
} }
} }
void VisualNavbar::fetchAndPaintData() void VisualNavbar::fetchAndPaintData()
{ {
fetchData(); fetchStats();
fillData(); updateGraphicsScene();
} }
void VisualNavbar::fetchData() void VisualNavbar::fetchStats()
{ {
statsWidth = graphicsView->width(); stats = Core()->getBlockStatistics(statsWidth);
stats = Core()->getBlockStatistics((unsigned int)statsWidth);
} }
enum class DataType: int { Empty, Code, String, Symbol, Count }; enum class DataType: int { Empty, Code, String, Symbol, Count };
void VisualNavbar::fillData() void VisualNavbar::updateGraphicsScene()
{ {
graphicsScene->clear(); graphicsScene->clear();
xToAddress.clear(); xToAddress.clear();

View File

@ -28,8 +28,8 @@ public slots:
private slots: private slots:
void fetchAndPaintData(); void fetchAndPaintData();
void fetchData(); void fetchStats();
void fillData(); void updateGraphicsScene();
void drawCursor(); void drawCursor();
void on_seekChanged(RVA addr); void on_seekChanged(RVA addr);
@ -40,13 +40,11 @@ private:
MainWindow *main; MainWindow *main;
BlockStatistics stats; BlockStatistics stats;
int statsWidth; unsigned int statsWidth = 0;
unsigned int previousWidth = 0;
QList<XToAddress> xToAddress; QList<XToAddress> xToAddress;
// Used to check whether the width changed. If yes we need to re-initialize the scene (slow)
int previousWidth = -1;
RVA localXToAddress(double x); RVA localXToAddress(double x);
double addressToLocalX(RVA address); double addressToLocalX(RVA address);
QList<QString> sectionsForAddress(RVA address); QList<QString> sectionsForAddress(RVA address);