Optimize resetOptimalWidth()

Don't call this method directly on every demand, but schedule
a call instead and invoke it once after the current call
returns back to the main loop.

The single call may cost up to ~20ms, and when we call it for
every target having 5000 targets, the total cost is up to ~10 seconds
(every call removes one items, so subsequent calls take a bit
less time). This happens on shutdown when Qt6 project was loaded.
The shutdown time went down from ~15 seconds to ~4 seconds with
this patch.

Change-Id: Id821d72cd8e1dd949112d9167b7736a267b221fc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-10-08 12:24:45 +02:00
parent de3e33a76b
commit a7b9ee22dd

View File

@@ -238,6 +238,18 @@ public:
protected:
void resetOptimalWidth()
{
if (m_resetScheduled)
return;
m_resetScheduled = true;
QMetaObject::invokeMethod(this, &SelectorView::doResetOptimalWidth, Qt::QueuedConnection);
}
private:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
void doResetOptimalWidth()
{
m_resetScheduled = false;
int width = 0;
QFontMetrics fn(font());
theModel()->forItemsAtLevel<1>([this, &width, &fn](const GenericItem *item) {
@@ -246,12 +258,9 @@ protected:
setOptimalWidth(width);
}
private:
void keyPressEvent(QKeyEvent *event) override;
void keyReleaseEvent(QKeyEvent *event) override;
int m_maxCount = 0;
int m_optimalWidth = 0;
bool m_resetScheduled = false;
};
class ProjectListView : public SelectorView