From 1bddb4ad7d33ba92ce4387bcaba55c2489dc6615 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 30 Oct 2017 15:31:25 +0100 Subject: QApplication::topLevelWidgets(): Avoid allocation of list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use the QSet QWidgetPrivate::allWidgets directly instead of calling QApplication::allWidgets(), which allocates a QList. Change-Id: I16d289030cecefae7811d4b2c94f865f46f700d5 Reviewed-by: Marc Mutz Reviewed-by: MÃ¥rten Nordheim --- src/widgets/kernel/qapplication.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/widgets/kernel/qapplication.cpp b/src/widgets/kernel/qapplication.cpp index 58f63c0fed..c922aecceb 100644 --- a/src/widgets/kernel/qapplication.cpp +++ b/src/widgets/kernel/qapplication.cpp @@ -111,6 +111,9 @@ #include +#include +#include + //#define ALIEN_DEBUG static void initResources() @@ -1658,12 +1661,12 @@ void QApplicationPrivate::notifyWindowIconChanged() QWidgetList QApplication::topLevelWidgets() { QWidgetList list; - QWidgetList all = allWidgets(); - - for (QWidgetList::ConstIterator it = all.constBegin(), cend = all.constEnd(); it != cend; ++it) { - QWidget *w = *it; - if (w->isWindow() && w->windowType() != Qt::Desktop) - list.append(w); + if (QWidgetPrivate::allWidgets != nullptr) { + const auto isTopLevelWidget = [] (const QWidget *w) { + return w->isWindow() && w->windowType() != Qt::Desktop; + }; + std::copy_if(QWidgetPrivate::allWidgets->cbegin(), QWidgetPrivate::allWidgets->cend(), + std::back_inserter(list), isTopLevelWidget); } return list; } -- cgit v1.2.3