QApplication::topLevelWidgets(): Avoid allocation of list

Use the QSet QWidgetPrivate::allWidgets directly instead of
calling QApplication::allWidgets(), which allocates a QList.

Change-Id: I16d289030cecefae7811d4b2c94f865f46f700d5
Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Friedemann Kleint 2017-10-30 15:31:25 +01:00
parent c50362597a
commit 1bddb4ad7d

View File

@ -111,6 +111,9 @@
#include <qtwidgets_tracepoints_p.h>
#include <algorithm>
#include <iterator>
//#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;
}