From a7b9ee22ddcf2ee012f5225c8a8c5834dc916e73 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Fri, 8 Oct 2021 12:24:45 +0200 Subject: [PATCH] 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 --- .../miniprojecttargetselector.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/plugins/projectexplorer/miniprojecttargetselector.cpp b/src/plugins/projectexplorer/miniprojecttargetselector.cpp index b73d12c5789..44fc5ae511a 100644 --- a/src/plugins/projectexplorer/miniprojecttargetselector.cpp +++ b/src/plugins/projectexplorer/miniprojecttargetselector.cpp @@ -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