mirror of
https://github.com/rizinorg/cutter.git
synced 2025-01-31 08:37:26 +00:00
Optimize VisualNavbar Stats Loading
This commit is contained in:
parent
b10d132237
commit
125006b1c2
@ -1537,6 +1537,11 @@ QList<SearchDescription> CutterCore::getAllSearch(QString search_for, QString sp
|
||||
|
||||
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();
|
||||
|
||||
BlockStatistics ret;
|
||||
|
@ -65,32 +65,54 @@ VisualNavbar::VisualNavbar(MainWindow *main, QWidget *parent) :
|
||||
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)
|
||||
{
|
||||
Q_UNUSED(event);
|
||||
|
||||
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();
|
||||
previousWidth = this->width();
|
||||
} else if (previousWidth != w) {
|
||||
this->previousWidth = w;
|
||||
updateGraphicsScene();
|
||||
}
|
||||
}
|
||||
|
||||
void VisualNavbar::fetchAndPaintData()
|
||||
{
|
||||
fetchData();
|
||||
fillData();
|
||||
fetchStats();
|
||||
updateGraphicsScene();
|
||||
}
|
||||
|
||||
void VisualNavbar::fetchData()
|
||||
void VisualNavbar::fetchStats()
|
||||
{
|
||||
statsWidth = graphicsView->width();
|
||||
stats = Core()->getBlockStatistics((unsigned int)statsWidth);
|
||||
stats = Core()->getBlockStatistics(statsWidth);
|
||||
}
|
||||
|
||||
enum class DataType: int { Empty, Code, String, Symbol, Count };
|
||||
|
||||
void VisualNavbar::fillData()
|
||||
void VisualNavbar::updateGraphicsScene()
|
||||
{
|
||||
graphicsScene->clear();
|
||||
xToAddress.clear();
|
||||
|
@ -28,8 +28,8 @@ public slots:
|
||||
|
||||
private slots:
|
||||
void fetchAndPaintData();
|
||||
void fetchData();
|
||||
void fillData();
|
||||
void fetchStats();
|
||||
void updateGraphicsScene();
|
||||
void drawCursor();
|
||||
void on_seekChanged(RVA addr);
|
||||
|
||||
@ -40,13 +40,11 @@ private:
|
||||
MainWindow *main;
|
||||
|
||||
BlockStatistics stats;
|
||||
int statsWidth;
|
||||
unsigned int statsWidth = 0;
|
||||
unsigned int previousWidth = 0;
|
||||
|
||||
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);
|
||||
double addressToLocalX(RVA address);
|
||||
QList<QString> sectionsForAddress(RVA address);
|
||||
|
Loading…
Reference in New Issue
Block a user