From fb7670f193712fae2d4c03d6ee2a6c30101b886f Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 6 Apr 2025 14:32:07 +0200 Subject: [PATCH] QMainWindowLayout: de-pessimize ~QMainWindowToolBar As the code comment says, ~QMainWindowTabBar will removeOne(this) from QMainWindowLayout::unusedTabBars. It doesn't assert that it was included in it, or something special like that. So we can optimize the whole thing by making sure that ~QMainWindowTabBar doesn't find anything to remove here, avoiding a detach from the copy 'bars' and potentially also avoiding quadratic behavior, as we delete the items in order. Found by Coverity, but it only saw this as an optimization opportunity because it doesn't understand that the copy is needed. Amends 23357e59bb4dc54e76a237b290aa64a620db2ea1. Pick-to: 6.9 6.8 6.5 Coverity-Id: 479705 Change-Id: I6c31e028c0c39813768e8c71076471b39bd8ef5a Reviewed-by: Axel Spoerl --- src/widgets/widgets/qmainwindowlayout.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 869fc49c021..83626b251a7 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -2733,8 +2733,9 @@ QMainWindowLayout::~QMainWindowLayout() #if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) // unusedTabBars contains unparented tab bars, which need to be removed manually. - // ~QMainWindowTabBar() removes the barĀ from unusedTabBars => call qDeleteAll() on a copy. - const auto bars = unusedTabBars; + // ~QMainWindowTabBar() attempts to remove the barĀ from unusedTabBars + // => move it out of the way first. + const auto bars = std::move(unusedTabBars); qDeleteAll(bars); #endif // QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) }