diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-10-08 12:24:45 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2021-10-08 12:09:25 +0000 |
commit | a7b9ee22ddcf2ee012f5225c8a8c5834dc916e73 (patch) | |
tree | 955d21400bb403fdf0eed43200bd69eaaca2fad3 | |
parent | de3e33a76b10ec59d9603655710f08988365f3a9 (diff) |
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>
-rw-r--r-- | src/plugins/projectexplorer/miniprojecttargetselector.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/plugins/projectexplorer/miniprojecttargetselector.cpp b/src/plugins/projectexplorer/miniprojecttargetselector.cpp index b73d12c578..44fc5ae511 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 |