From 2b50c8bec086ae975ac5152e08f6b3dcf76306a0 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 2 Jul 2021 08:32:09 +0200 Subject: QObject: optimize the common case of findChildren(QString()) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: MÃ¥rten Nordheim --- tests/auto/corelib/kernel/qobject/tst_qobject.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests/auto/corelib/kernel/qobject/tst_qobject.cpp') diff --git a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp index f5c16faa56..3d52478299 100644 --- a/tests/auto/corelib/kernel/qobject/tst_qobject.cpp +++ b/tests/auto/corelib/kernel/qobject/tst_qobject.cpp @@ -755,6 +755,8 @@ void tst_QObject::findChildren() op = o.findChild("unnamed", Qt::FindDirectChildrenOnly); QCOMPARE(op, static_cast(0)); + l = o.findChildren(Qt::FindDirectChildrenOnly); + QCOMPARE(l.size(), 5); l = o.findChildren(QString(), Qt::FindDirectChildrenOnly); QCOMPARE(l.size(), 5); l = o.findChildren("", Qt::FindDirectChildrenOnly); -- cgit v1.2.3