From 9fea0c613edee452ded1d61174088560cbbde10b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 2 Jun 2022 20:37:11 +0200 Subject: [PATCH] QCOMPARE/QVERIFY: fix huge pessimisation in QTestResult::reportResult MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The old code allocated a stack buffer, but asked the runtime to zero-initialize it. That's 1KiB of writes to the stack on every QCOMPARE and QVERIFY before any actual work is done. Fixing this little laissez-faire to just initialize the first character in the buffer results in nice little speedups of ~40%. This fixes the issue in reportResult(), a Cut'n'paste from compare() and verify(), which have since been fixed by a previous commit. Change-Id: I5cad57299490925b88e768dc751304699274db2e Reviewed-by: Tor Arne Vestbø Reviewed-by: Thiago Macieira Reviewed-by: Mårten Nordheim --- src/testlib/qtestresult.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/testlib/qtestresult.cpp b/src/testlib/qtestresult.cpp index 5c947301cc..14d344f381 100644 --- a/src/testlib/qtestresult.cpp +++ b/src/testlib/qtestresult.cpp @@ -629,7 +629,8 @@ bool QTestResult::reportResult(bool success, qxp::function_ref l const char *failureMessage) { const size_t maxMsgLen = 1024; - char msg[maxMsgLen] = {'\0'}; + char msg[maxMsgLen]; + msg[0] = '\0'; QTEST_ASSERT(lhsExpr); QTEST_ASSERT(rhsExpr);