diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2021-07-02 08:32:09 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2021-07-13 16:57:31 +0200 |
commit | 2b50c8bec086ae975ac5152e08f6b3dcf76306a0 (patch) | |
tree | 656fded2be7e3e7d8d7d7c9336da8e1bad0d7ac7 /src/widgets/widgets | |
parent | 1edb51a315c4ab307878d6620d8d7484cc080d09 (diff) |
QObject: optimize the common case of findChildren(QString())
Outside tests, all in-tree callers of QObject::findChildren() pass no
name to match, and in my experience that is also true for the vast
majority of out-of-tree users.
Avoid the temporary QString creation in the caller and the repeated
QString::isNull() checks in the implementation by overloading
findChildren() without a name argument and checking for name.isNull()
only once, forking off into separate helper functions.
Adjust in-tree callers that used an explicit `QString()` argument in
order to pass options, which goes to show that `name` should never
have been the first argument of findChilden() in the first place, even
though I appreciate the symmetry with findChild() (the use-cases of
which, however, are radically different).
Change a `findChildren().size() == 0` call found while scanning for
findChildren() calls to `!findChild()` as a drive-by.
Modernize loops in the various qt_qFindChild{,ren}_helper() overloads
to match how the new code looks.
[ChangeLog][QtCore][QObject] Added findChildren() overload taking no
name (thus optimizing this common case).
Change-Id: Ifc56e5438023d079b40c67f11ae274a3e128ad5e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/widgets/widgets')
-rw-r--r-- | src/widgets/widgets/qdockarealayout.cpp | 4 | ||||
-rw-r--r-- | src/widgets/widgets/qmainwindowlayout.cpp | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/src/widgets/widgets/qdockarealayout.cpp b/src/widgets/widgets/qdockarealayout.cpp index 7776ae6613..ee200de57d 100644 --- a/src/widgets/widgets/qdockarealayout.cpp +++ b/src/widgets/widgets/qdockarealayout.cpp @@ -2607,7 +2607,7 @@ void QDockAreaLayout::removePlaceHolder(const QString &name) if (!index.isEmpty()) remove(index); const auto groups = - mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly); + mainWindow->findChildren<QDockWidgetGroupWindow *>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *dwgw : groups) { index = dwgw->layoutInfo()->indexOfPlaceHolder(name); if (!index.isEmpty()) { @@ -3045,7 +3045,7 @@ bool QDockAreaLayout::restoreDockWidget(QDockWidget *dockWidget) { QDockAreaLayoutItem *item = nullptr; const auto groups = - mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly); + mainWindow->findChildren<QDockWidgetGroupWindow *>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *dwgw : groups) { QList<int> index = dwgw->layoutInfo()->indexOfPlaceHolder(dockWidget->objectName()); if (!index.isEmpty()) { diff --git a/src/widgets/widgets/qmainwindowlayout.cpp b/src/widgets/widgets/qmainwindowlayout.cpp index 59e2e4e57a..18dd05e63b 100644 --- a/src/widgets/widgets/qmainwindowlayout.cpp +++ b/src/widgets/widgets/qmainwindowlayout.cpp @@ -431,7 +431,7 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty() } // Make sure to reparent the possibly floating or hidden QDockWidgets to the parent - const auto dockWidgets = findChildren<QDockWidget *>(QString(), Qt::FindDirectChildrenOnly); + const auto dockWidgets = findChildren<QDockWidget *>(Qt::FindDirectChildrenOnly); for (QDockWidget *dw : dockWidgets) { bool wasFloating = dw->isFloating(); bool wasHidden = dw->isHidden(); @@ -451,7 +451,7 @@ void QDockWidgetGroupWindow::destroyOrHideIfEmpty() dw->show(); } #if QT_CONFIG(tabbar) - const auto tabBars = findChildren<QTabBar *>(QString(), Qt::FindDirectChildrenOnly); + const auto tabBars = findChildren<QTabBar *>(Qt::FindDirectChildrenOnly); for (QTabBar *tb : tabBars) tb->setParent(parentWidget()); #endif @@ -1056,7 +1056,7 @@ void QMainWindowLayoutState::saveState(QDataStream &stream) const dockAreaLayout.saveState(stream); #if QT_CONFIG(tabbar) const QList<QDockWidgetGroupWindow *> floatingTabs = - mainWindow->findChildren<QDockWidgetGroupWindow *>(QString(), Qt::FindDirectChildrenOnly); + mainWindow->findChildren<QDockWidgetGroupWindow *>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *floating : floatingTabs) { if (floating->layoutInfo()->isEmpty()) @@ -1835,7 +1835,7 @@ QDockAreaLayoutInfo *QMainWindowLayout::dockInfo(QWidget *widget) if (info) return info; const auto groups = - parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly); + parent()->findChildren<QDockWidgetGroupWindow*>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *dwgw : groups) { info = dwgw->layoutInfo()->info(widget); if (info) @@ -2104,7 +2104,7 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem) previousPath = currentHoveredFloat->layoutInfo()->indexOf(widget); // Let's remove the widget from any possible group window const auto groups = - parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly); + parent()->findChildren<QDockWidgetGroupWindow*>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *dwgw : groups) { if (dwgw == currentHoveredFloat) continue; @@ -2134,7 +2134,7 @@ bool QMainWindowLayout::plug(QLayoutItem *widgetItem) #if QT_CONFIG(dockwidget) // Let's remove the widget from any possible group window const auto groups = - parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly); + parent()->findChildren<QDockWidgetGroupWindow*>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *dwgw : groups) { QList<int> path = dwgw->layoutInfo()->indexOf(widget); if (!path.isEmpty()) @@ -2730,7 +2730,7 @@ void QMainWindowLayout::applyState(QMainWindowLayoutState &newState, bool animat #if QT_CONFIG(dockwidget) && QT_CONFIG(tabwidget) QSet<QTabBar*> used = newState.dockAreaLayout.usedTabBars(); const auto groups = - parent()->findChildren<QDockWidgetGroupWindow*>(QString(), Qt::FindDirectChildrenOnly); + parent()->findChildren<QDockWidgetGroupWindow*>(Qt::FindDirectChildrenOnly); for (QDockWidgetGroupWindow *dwgw : groups) used += dwgw->layoutInfo()->usedTabBars(); |