forked from qt-creator/qt-creator
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:
@@ -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
|
||||
|
Reference in New Issue
Block a user