Commit Graph

689 Commits

Author SHA1 Message Date
Marc Mutz
47375a213f QMimeDatabase benchmark: port away from Q_FOREACH
The original code duplicated contained elements of a QStringList by
repeated appending it to itself, preventing the container from being
marked const.

Instead, keep a list of unique mime-types, and iterate over the list
eight times.

As a drive-by, port from QList to a C array ("never use a
dynamically-sized container for statically-sized data"), use u""_s
UDLs (since we're touching almost all lines of the function, anyway,
also in the unrelated mimeTypeForName() call).

This allows porting the Q_FOREACH loop (which anyway cannot deal with
C arrays) to a ranged for one (which can).

Pick-to: 6.6 6.5
Task-number: QTBUG-115839
Change-Id: I844ae38104bb2980ea194b85f9017a3e95791ea2
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-14 23:11:54 +03:00
Marc Mutz
d4ba159148 QtWidgets benchmarks: port remaining users away from Q_FOREACH
These are all trivial: all are over (already or newly-made) const
local variables.

We don't have a mechanism to mark a subtree as Q_FOREACH-free, and
adding QT_NO_FOREACH to each executable is overkill, so we just have
to hope that no new uses are being introduced until we can mark the
whole QtBase module as Q_FOREACH-free.

Pick-to: 6.6 6.5
Task-number: QTBUG-115803
Change-Id: I13dc176756633674bab8c93a342ecdba6c5dd23e
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2023-08-14 23:11:54 +03:00
Dennis Oberst
3c38efbfe4 QByteArray: use new assign() in operator=(const char *)
operator=(~) and assign(~) share similar names but, until now, have not
shared the same functionality. This patch introduces the usage of
QByteArray::assign() within the non-sharing assignment operator to
effectively boost efficiency by reusing the available capacity.

Since these assignment operators are frequently used in many places,
both within Qt and non-Qt code, this patch comes with benchmarks.

The preview of the benchmark results are compared with this patch and
before this patch. The findings indicate a slight enhancement in
performance associated with the assignment operator. Despite the results
displaying only a minor improvement, progress has been made. Therefore
use assign(QByteArrayView) as replacement.

(x86_64-little_endian-lp64 shared (dynamic) release build (O3); by
gcc 13.2.1, endeavouros ; 13th Gen Intel(R) Core(TM) i9-13900K

benchmarks executed with -perf -iterations 1000000

  * The last value at the EOL represent the string size.

QByteArray &operator=(const char *ch) (current)
  65    cycles/iter; 317  instructions/iter; 16.0 nsec/iter (5)
  71.7  cycles/iter; 383  instructions/iter; 13.0 nsec/iter (10)
  59.8  cycles/iter; 318  instructions/iter; 10.9 nsec/iter (20)
  70.8  cycles/iter; 340  instructions/iter; 12.9 nsec/iter (50)
  80.2  cycles/iter; 419  instructions/iter; 14.6 nsec/iter (100)
  164.2 cycles/iter; 899  instructions/iter; 29.9 nsec/iter (500)
  260.5 cycles/iter; 1522 instructions/iter; 45.6 nsec/iter (1'000)

QByteArray &operator=(const char *ch) (before)
  66.8  cycles/iter; 317  instructions/iter; 16.9 nsec/iter (5)
  76.5  cycles/iter; 383  instructions/iter; 13.9 nsec/iter (10)
  63.7  cycles/iter; 318  instructions/iter; 11.6 nsec/iter (20)
  71.6  cycles/iter; 344  instructions/iter; 13.0 nsec/iter (50)
  77.5  cycles/iter; 419  instructions/iter; 14.1 nsec/iter (100)
  143.4 cycles/iter; 893  instructions/iter; 26.1 nsec/iter (500)
  270.8 cycles/iter; 1516 instructions/iter; 48.2 nsec/iter (1'000)

Task-number: QTBUG-106201
Change-Id: I0745c33f0f61f1d844a60960cc55f565320d5945
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-08-11 14:11:44 +02:00
Marc Mutz
17dad4b88b QMimeDatabase benchmark: measure only what it pertinent
Drag the QCOMPARE (which even dynamically allocated a QString
fromLatin1()) out of the QBENCHMARK loop. Testing performance of
QString::fromLatin1() and/or qCompare() is not pertinent to the task
at hand, which, ideally, doesn't involve any memory allocations, so
there's at least the chance that this skewed the result noticably.

Didn't run the benchmark as this was developed on an asan build.

Yes, this breaks comparability with the stone-age measurements
reported in comments there, so sue me.

As a drive-by, replace the fromLatin1() with a u_s UDL.

Pick-to: 6.6 6.5
Change-Id: I9b2a8b2e3596ec9b07c6b4ea369257b1a86e09db
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: David Faure <david.faure@kdab.com>
2023-08-09 23:57:21 +02:00
Marc Mutz
0e5de43e10 QWidget benchmark: port away from Q_FOREACH
This one isn't trivial, but straight-forward: the only place the
container is modified is in fill(). Like the setOpaqueChildren()
function, this is only called from top-level test functions, and, in
particular, not from event handlers (setAttribute() sends events).

That fill() doesn't clear() the container, even though the single
UpdateWidget instance is being reused across test functions, looks
wrong, but doesn't invalidate this analysis.

Task-number: QTBUG-115803
Change-Id: I284a19da2fe476278986c61810dd334fc73034b0
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-08-08 17:08:00 +02:00
Marc Mutz
62312e6674 GraphicsViewBenchmark: port from QList/Q_FOREACH to initializer_list/ranged-for
This is more readable and at the same time helps to eradicate some
more Q_FOREACH uses for an eventual global QT_NO_FOREACH for all Qt
sources (QTBUG-115796).

Task-number: QTBUG-115803
Change-Id: I9cbe76bee8a6306fab0c0bc94cd874405ca825ba
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2023-08-08 16:03:28 +02:00
Thiago Macieira
4a5f3c8b93 CMake: remove check for cxx11_future
Everyone must have this by now. This test was 1193 ms of CMake time.

Since this was a PUBLIC feature, I've left it around with a constant
condition.

Change-Id: Ifbf974a4d10745b099b1fffd177754538bbff245
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-08-02 12:36:18 -07:00
Edward Welbourne
07e4015687 Simplify (and fix) initialization of a list of time-zones
Looping over the entries had a typo in it and was quite unnecessary,
as it just made a fresh copy of a list we already had.

Pick-to: 6.6 6.5 6.2 5.15
Change-Id: I0f3023b06163e5854d425d816e465785cda5fc91
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-07-19 22:50:32 +02:00
Volker Hilsheimer
e4e186771e Fix warning, remove unused variable
Change-Id: I77167919a2382f38d10694ce14ccd209cc7c2377
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
Reviewed-by: Oliver Eftevaag <oliver.eftevaag@qt.io>
2023-05-22 16:45:27 +02:00
Ivan Solovev
9b4b32ec98 Long live QtFuture::makeReadyVoidFuture() and QtFuture::makeReadyValueFuture()
[ChangeLog][QtCore][QFuture] Added QtFuture::makeReadyVoidFuture()
and QtFuture::makeReadyValueFuture().

Basically, these methods behave like QtFuture::makeReadyFuture(), but
QtFuture::makeReadyValueFuture() does not have a "const QList<T> &"
specialization returning QFuture<T> instead of QFuture<QList<T>>,
which allows it to always behave consistently.

This patch also introduces usage of the new methods around qtbase.

Task-number: QTBUG-109677
Change-Id: I89df8b26d82c192baad69efb5df517a8b182995f
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-04-05 13:38:15 +02:00
Christian Ehrlicher
dbcad6392b SQL/Benchmarks: cleanup
The benchmarks were only copied from the tests without a proper cleanup
- therefore clean them up now.

Change-Id: I0285de3fd2b67c21e732d7f3f9d1f4937965be81
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-04-05 05:37:32 +01:00
Marc Mutz
eb260c132a tst_bench_QCryptographicHash: use resultView()
Don't benchmark the creation of the QByteArray from the internal
buffer, that's not interesting.

Call resultView() instead of result().

On the one hand, this skews comparisons with older benchmark data.

OTOH, result() used to be the fastest way to get the result out of
QCryptographicHash or QMessageAuthenticationCode, and now it's
resultView(), so in a way, it still is a fair comparison.

Pick-to: 6.5
Change-Id: I864b2f88f01e426c5d0967f57199e13dd7cb29f8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-31 10:32:45 +01:00
Marc Mutz
0eccfe5e39 tst_bench_QCryptographicHash: port from std::function to qxp::function_ref
Because we can, and because function_ref is never null.

Pick-to: 6.5
Change-Id: If71f98860d72eaa8cf8a93bb3c59a0260d3c7660
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-31 10:32:45 +01:00
Marc Mutz
f1b264f9ac tst_bench_QCryptographicHash: QSKIP unsupported algorithms
With the OpenSSL 3 backend, some algorithms may not be available. Skip
benchmarking them.

Pick-to: 6.5
Change-Id: I1275332993fe15c007410e25acf59f5e3ec27894
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-31 10:32:45 +01:00
Marc Mutz
3aaae083f7 tst_bench_QCryptographicHash: add benchmarks for QMessageAuthenticationCode
We could add a tst_QMessageAuthenticationCode, but it would have to
duplicate a lot of the tst_QCryptographicHash machinery, so just add
it here.

Pick-to: 6.5 6.2 5.15
Change-Id: Icc60de865c72c5e423cb3be57f58297c522791f7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-31 10:32:45 +01:00
Marc Mutz
25c5452c26 tst_bench_QCryptographicHash: swallow result() return values
As usual, assign them to a [[maybe_unused]] variable, to avoid
potential future [[nodiscard]] problems, and to indicate to
readers of the code that there's a result that's being returned,
we're just not interested in it.

Pick-to: 6.5 6.2
Change-Id: I2bd47ca98418092ca885d50a1a6417a21a612a85
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-23 16:14:12 +00:00
Marc Mutz
d0149e2404 tst_bench_QCryptographicHash: use QMetaEnum trick
... conveniently wrapped in a generator, to not have to keep an
algoname() function in sync with QCryptographicHash::Algorithm.

The MaxCryptoAlgorithm constant was already stale following the
addition of BLAKE2b/s algorithms in
5d69aa3ee1.

Also make the data-driven tests have an actual Algorithm column
(was: int) to minimize casting.

Pick-to: 6.5 6.2 5.15
Change-Id: I89a6098e512a72f623fd50a6f88fc351c7bb1418
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-03-23 16:14:12 +00:00
Marc Mutz
f68b9e432b tst_bench_QCryptographicHash: port to QTest::addRow()
Allows using printf-style tag formatting.

Pick-to: 6.5 6.2 5.15
Change-Id: Icb8014dd476a32791c662a15b209dbb3bd7d6c96
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-23 17:14:11 +01:00
Volker Hilsheimer
643b6e5b29 Silence warnings from unused variables
Use them, or replace them with existing constants.

Pick-to: 6.5
Change-Id: I808028296305e15b68aecb1f961ba6a85b8e9cc7
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-21 07:46:27 +01:00
Ahmad Samir
f325bdacb6 Replace ushort*/uint* with char16_t*/char32_t* in private API [1]
Task-number: QTBUG-110403
Pick-to: 6.5
Change-Id: Ie20a831f22212d56659cf3c6940d17134ab5f2c5
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-15 20:25:57 +00:00
Ahmad Samir
0d29a406f7 QThread: add sleep(std::chrono::nanoseconds) overload
All the other overloads are implemented using the new one.

Windows change relies on the pre-check in the code review making sure it
compiles.

[ChangeLog][QtCore][QThread] Added sleep(std::chrono::nanoseconds)
overload.

Task-number: QTBUG-110059
Change-Id: I9a4f4bf09041788ec9275093b6b8d0386521e286
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-13 23:26:28 +02:00
Christian Ehrlicher
18bd15a9ea SQL/Tests: remove safeDropTable() / add helper class
Add a helper class which makes sure that the used table does not exist
before usage (e.g. due to leftovers from previous tests) and is properly
cleaned up on exit. This also allows to remove all usages of
safeDropTable().

Change-Id: Iefeffbd10e2f2f67985183ea822d7b6dd2b80be7
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2023-03-12 17:21:17 +01:00
Volker Hilsheimer
cacc53e427 Silence warning, initialize variables before using
Pick-to: 6.5
Change-Id: I0e7db95bac48b5d79897402f23157d00c4abbdff
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-03-06 22:34:39 +01:00
Ahmad Samir
2a495c2596 QTestEventLoop: add enterLoop(std::chrono::milliseconds) overload
Task-number: QTBUG-110059
Change-Id: Ibf1d76afd313e390103be4a22e44af7fb41ace1b
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-03-03 21:36:48 +02:00
Edward Welbourne
4931fe9b02 Fix parsing of numbers to cope with non-single-character tokens
In some locales signs and the exponent are not single character
tokens. Replace QLocaleData::numericToCLocale() with a tokenizer that
will cope with this. At the same time, cache the locale data needed in
support of that, so that we don't repeatedly recreate QString()
objects just to compare them against input tokens.

The caching class is inspired by Thiago's proposal for fixing the
performance, which also inspires the optimization of the C locale in
the tokenizer used here.

Add some testing that round-tripping numbers via strings works for the
locales with signs and exponents that use more than one character.

Task-number: QTBUG-107801
Change-Id: I9fd8409a371ed62ed969d9ebc8b09584e752f7fb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-02-24 13:37:07 +01:00
Friedemann Kleint
97bfacf1e2 tests: Remove remains of qmake conversion from CMakeLists.txt files
Pick-to: 6.5
Change-Id: I8d106554bb86ac1ec9bb7a4083de4c376bcbab1d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
2023-02-17 21:56:49 +01:00
David Faure
eae031d5c3 Fix QDir benchmark to do meaningful things
* Include the creation of the QDir inside QBENCHMARK, otherwise
  the it can hit the cached code path where subsequent runs return
  results much faster.

* Same for the opendir()/readdir() test: if opendir() isn't called
  again, readdir() will just return null right away.

These two issues led to nonsense results like 0.00025 msecs per
iteration, doing nothing is really quick.

While at it, port the cleanup code to QDir::removeRecursively()

Pick-to: 6.5 6.4 6.2
Change-Id: Ic1bdd92d41efe1f6d0eaaa33eca066cb7d19fc93
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2023-02-07 13:33:01 +01:00
David Faure
c609b8dba0 QSortFilterProxyModel: port to PMF connects for performance reasons
BEFORE:
   0.21 msecs per iteration (total: 56, iterations: 256)
   801,946 CPU cycles per iteration (total: 801,946, iterations: 1)

AFTER:
   0.084 msecs per iteration (total: 87, iterations: 1024)
   300,259 CPU cycles per iteration (total: 300,259, iterations: 1)

Change-Id: I5b2703c217bb25e18f1d9f6a1eda19c60e1edcb0
Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
2023-02-02 20:43:59 +01:00
Edward Welbourne
8c8d6ff7b6 Deprecate QDateTime methods using plain Qt::TimeSpec
As foreshadowed when QDateTime adapted to route all QTimeSpec use
through QTimeZone, this commit deprecates the old API in favor of the
newly more capable QTimeZone-based API.

Fixes: QTBUG-108199
Change-Id: I9a3f9f94d4a5d8cc229db72b3e4731a9e318a076
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-12-10 06:39:33 +01:00
Edward Welbourne
3f282e8896 Adapt corelib to use QTimeZone in place of Qt::TimeSpec
This saves (mostly in corelib/time/) some complications that used to
arise from needing different code-paths for different time-specs.

Task-number: QTBUG-108199
Change-Id: I5dbd09859fce7599f1ba761f8a0bfc4633d0bef9
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-12-09 16:16:48 +01:00
Øystein Heskestad
b977ae371a Add In-place utf-8 case-insensitive comparisons
Also add optimizations for more string comparisons and add tests and
benchmarks.

[ChangeLog][QtCore][QString] Added utf-8 case-insensitive comparisons

Fixes: QTBUG-100235
Change-Id: I7c0809c6d80c00e9a5d0e8ac3ebb045cf7004a30
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-12-02 11:35:49 +01:00
Edward Welbourne
cf36db4df9 Add benchmarks for QLocale number parsing
Based on those for QString, but with locale variation and exercising
some of the locales with multi-character signs and exponents.

Pick-to: 6.4 6.2 5.15
Change-Id: Id0253449f9abcc154285f89337aa0e26dd69900d
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-11-11 16:32:52 +01:00
Edward Welbourne
7fef433004 Add benchmarks for QString number parsing
Based on the tests for QString::number(), but run in reverse, with
some embelishments. Also moved some shared code from number_*_data()
to their shared number_integer_common template.

Pick-to: 6.4 6.2 5.15
Change-Id: I74e7082372166c3cdbcd6bcbc31f9003e07cbcbc
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-11-11 16:32:52 +01:00
Marc Mutz
1c6bf3e09e Port from container::count() and length() to size() - V5
This is a semantic patch using ClangTidyTransformator as in
qtbase/df9d882d41b741fef7c5beeddb0abe9d904443d8, but extended to
handle typedefs and accesses through pointers, too:

    const std::string o = "object";

    auto hasTypeIgnoringPointer = [](auto type) { return anyOf(hasType(type), hasType(pointsTo(type))); };

    auto derivedFromAnyOfClasses = [&](ArrayRef<StringRef> classes) {
        auto exprOfDeclaredType = [&](auto decl) {
            return expr(hasTypeIgnoringPointer(hasUnqualifiedDesugaredType(recordType(hasDeclaration(decl))))).bind(o);
        };
        return exprOfDeclaredType(cxxRecordDecl(isSameOrDerivedFrom(hasAnyName(classes))));
    };

    auto renameMethod = [&] (ArrayRef<StringRef> classes,
                            StringRef from, StringRef to) {
        return makeRule(cxxMemberCallExpr(on(derivedFromAnyOfClasses(classes)),
                            callee(cxxMethodDecl(hasName(from), parameterCountIs(0)))),
                        changeTo(cat(access(o, cat(to)), "()")),
                        cat("use '", to, "' instead of '", from, "'"));
    };

    renameMethod(<classes>, "count", "size");
    renameMethod(<classes>, "length", "size");

except that the on() matcher has been replaced by one that doesn't
ignoreParens().

a.k.a qt-port-to-std-compatible-api V5 with config Scope: 'Container'.

Added two NOLINTNEXTLINEs in tst_qbitarray and tst_qcontiguouscache,
to avoid porting calls that explicitly test count().

Change-Id: Icfb8808c2ff4a30187e9935a51cad26987451c22
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-11-03 14:59:24 +01:00
Johannes Kauffmann
a9fa999f79 tests: fix configuring with -no-feature-gui
Pick-to: 6.2 6.4
Change-Id: I99765d38c9c37f1fe17b15f7736e4c78c7ffac20
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
2022-10-29 01:04:09 +02:00
Johannes Kauffmann
30eac4a4f9 benchmarks: fix configuring with -no-feature-sql
With -no-feature-sql, CMake would error out because the target Qt6::Sql
didn't exist. Fix this by checking if the target exists.

Task-number: QTBUG-102480
Pick-to: 6.2 6.3 6.4
Change-Id: I411631acfd336ea699833954f86711067d160c04
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-10-25 16:39:25 +02:00
Yuhang Zhao
bea5649cd1 Windows: bump NTDDI_VERSION to latest version and remove some duplicated code
We have NTDDI_WIN10_NI (0x0A00000C) in the Win11 SDK (10.0.22621)
so bump the value in Qt (currently 0x0A00000B) to it.

And when searching for _WIN32_WINNT/WINVER/NTDDI_VERSION throughout
the whole qtbase codebase, I found some duplicated code, mostly
leftovers from the legacy time. Replace them with our own windows
header can achieve the same effect: we have defined all the necessary
macros to unblock the latest features. And place the header at the
top most place to include the macros as early as possible.

Change-Id: I37d9ac40ca9748208c7b2e89f374eda362dbefd6
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
2022-10-24 13:22:24 +08:00
Marc Mutz
fc76767692 Long live Q_UNREACHABLE_RETURN()!
This is a combination of Q_UNREACHABLE() with a return statement.

ATM, the return statement is unconditionally included. If we notice
that some compilers warn about return after __builtin_unreachable(),
then we can map Q_UNREACHABLE_RETURN(...) to Q_UNREACHABLE() without
having to touch all the code that uses explicit Q_UNREACHABLE() +
return.

The fact that Boost has BOOST_UNREACHABLE_RETURN() indicates that
there are compilers that complain about a lack of return after
Q_UNREACHABLE (we know that MSVC, ICC, and GHS are among them), as
well as compilers that complained about a return being present
(Coverity). Take this opportunity to properly adapt to Coverity, by
leaving out the return statement on this compiler.

Apply the macro around the code base, using a clang-tidy transformer
rule:

    const std::string unr = "unr", val = "val", ret = "ret";
    auto makeUnreachableReturn = cat("Q_UNREACHABLE_RETURN(",
                                    ifBound(val, cat(node(val)), cat("")),
                                    ")");
    auto ignoringSwitchCases = [](auto stmt) {
        return anyOf(stmt, switchCase(subStmt(stmt)));
    };

    makeRule(
       stmt(ignoringSwitchCases(stmt(isExpandedFromMacro("Q_UNREACHABLE")).bind(unr)),
            nextStmt(returnStmt(optionally(hasReturnValue(expr().bind(val)))).bind(ret))),
       {changeTo(node(unr), cat(makeUnreachableReturn,
                                ";")),  // TODO: why is the ; lost w/o this?
        changeTo(node(ret), cat(""))},
       cat("use ", makeUnreachableReturn))
    );

where nextStmt() is copied from some upstream clang-tidy check's
private implementation and subStmt() is a private matcher that gives
access to SwitchCase's SubStmt.

A.k.a. qt-use-unreachable-return.

There were some false positives, suppressed them with NOLINTNEXTLINE.

They're not really false positiives, it's just that Clang sees the
world in one way and if conditonal compilation (#if) differs for other
compilers, Clang doesn't know better. This is an artifact of matching
two consecutive statements.

I haven't figured out how to remove the empty line left by the
deletion of the return statement, if it, indeed, was on a separate
line, so post-processed the patch to remove all the lines matching
^\+ *$ from the diff:

  git commit -am meep
  git reset --hard HEAD^
  git diff HEAD..HEAD@{1} | sed '/^\+ *$/d' | recountdiff - | patch -p1

[ChangeLog][QtCore][QtAssert] Added Q_UNREACHABLE_RETURN() macro.

Change-Id: I9782939f16091c964f25b7826e1c0dbd13a71305
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-10-15 22:11:47 +02:00
Marc Mutz
aa37e67ef7 Port from qAsConst() to std::as_const()
We've been requiring C++17 since Qt 6.0, and our qAsConst use finally
starts to bother us (QTBUG-99313), so time to port away from it
now.

Since qAsConst has exactly the same semantics as std::as_const (down
to rvalue treatment, constexpr'ness and noexcept'ness), there's really
nothing more to it than a global search-and-replace, with manual
unstaging of the actual definition and documentation in dist/,
src/corelib/doc/ and src/corelib/global/.

Task-number: QTBUG-99313
Change-Id: I4c7114444a325ad4e62d0fcbfd347d2bbfb21541
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2022-10-11 23:17:18 +02:00
Marc Mutz
df9d882d41 Port from container.count()/length() to size()
This is semantic patch using ClangTidyTransformator:

  auto QtContainerClass = expr(hasType(namedDecl(hasAnyName(<classes>)))).bind(o)
  makeRule(cxxMemberCallExpr(on(QtContainerClass),
                             callee(cxxMethodDecl(hasAnyName({"count", "length"),
                                                  parameterCountIs(0))))),
           changeTo(cat(access(o, cat("size"), "()"))),
           cat("use 'size()' instead of 'count()/length()'"))

a.k.a qt-port-to-std-compatible-api with config Scope: 'Container'.

<classes> are:

    // sequential:
    "QByteArray",
    "QList",
    "QQueue",
    "QStack",
    "QString",
    "QVarLengthArray",
    "QVector",
    // associative:
    "QHash",
    "QMultiHash",
    "QMap",
    "QMultiMap",
    "QSet",
    // Qt has no QMultiSet

Change-Id: Ibe8837be96e8d30d1846881ecd65180c1bc459af
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2022-10-04 07:40:08 +02:00
Mårten Nordheim
7fea2d34fb Update tst_bench_qhash hash functions to use size_t
Pre-requisite for a fix for qHash. The Qt50String inherits from QString
and becomes ambiguous once it no longer goes through a catch-all
template function because qHash(QString, size_t) has a better match for
the second argument.

Pick-to: 6.2 6.4
Change-Id: I23c7afb1b3aa167d40dc4838e82b7763de015f6b
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
2022-09-27 23:30:30 +02:00
Marc Mutz
24675d1a94 tst_QDir_10000: add sorted_byName benchmark
Pick-to: 6.4 6.3 6.2
Change-Id: Ic30a6353c356f6613f2ef3720b99ebb3b0a7968e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-26 17:50:47 +00:00
Lucie Gérard
32df595275 Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: I5d3ef70a31235868b9be6cb479b7621bf2a8ba39
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-23 23:58:42 +02:00
Edward Welbourne
0ed8987078 Update QTimeZone benchmark's list of tested zones
It purports to be a list of those named in QDateTime's tests, but was
a bit out of date. In the process, sort them into somewhat coherent
order (to make it easier to verify whether one is missing next time I
check) and reformat.

Pick-to: 6.4 6.3 6.2
Change-Id: I16e7ded6f8b00e226513bd06d6174a79f7a0c675
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-16 15:02:22 +02:00
Lucie Gérard
fb1b20eab3 Add license headers to cmake files
CMakeLists.txt and .cmake files of significant size
(more than 2 lines according to our check in tst_license.pl)
now have the copyright and license header.

Existing copyright statements remain intact

Task-number: QTBUG-88621
Change-Id: I3b98cdc55ead806ec81ce09af9271f9b95af97fa
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-03 17:14:55 +02:00
Alexandru Croitor
4d22405e48 CMake: Don't use PUBLIC_LIBRARIES for tests and test helpers
Change-Id: I9b7404e1d3a78fe0726ec0f5ce1461f6c209e90d
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-28 14:46:53 +02:00
Marc Mutz
32925d0a85 tst_tostring: add benchmarks for QCOMPARE vs. QCOMPARE_EQ
There's currently no statistically-significant difference between the
two, due to a huge pessimistion in QTestLib where every QCOMPARE* and
QVERIFY writes 1KiB of data onto the stack before doing anything else,
so I'm not reporting numbers in this commit message.

Pick-to: 6.4
Task-number: QTBUG-98873
Task-number: QTBUG-98874
Change-Id: I233878596f0a8fe6b96360adb839fecd72c398a2
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2022-06-22 01:38:12 +00:00
Marc Mutz
882fc48b9e tst_bench_shared_ptr: fix build with BOOST_NO_EXCEPTIONS
If, for whatever reason, BOOST_NO_EXCEPTIONS is defined, the user of
the Boost libraries is supposed to provide a definition of
boost::throw_exception, which we didn't.

We used to run into this only on ubsan builds, but it seems we now
have the problem on a regular Ubuntu 22.04 build, too (cf. bugreport).

Fix by adding the necessary definitions.

Fixes: QTBUG-104083
Pick-to: 6.4 6.3
Change-Id: I9b061a158a5b77e8d286bd7b40312e5bc63ee8de
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-06-22 03:09:24 +02:00
Kai Köhne
9d2cc4dd76 Fix typos in docs and comments
Found by codespell

Pick-to: 6.4
Change-Id: Ie3e301a23830c773a2e9aff487c702a223d246eb
Reviewed-by: Nicholas Bennett <nicholas.bennett@qt.io>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2022-06-15 21:31:02 +02:00
Edward Welbourne
12eac545b6 Make two QDT benchmarks data-driven and add more rows
The QDateTime benchmark's toMSecsSinceEpoch() and
toMSecsSinceEpochTz() each iterated the 2010s and had 1950 and 2050
variants for two other decades. I want to also test some earlier
decades and do similar for create(), so combine the existing triplets
as three rows of a data-driven test for each triplet, add the new rows
and apply the same to create().

In the process, turn an enum used for qint64 constants into a set of
constexpr qint64 declarations.

Pick-to: 6.4 6.3 6.2 5.15
Task-number: QTBUG-104012
Change-Id: I2657346b65d96a7ef7503cd33c870b688ea5dbff
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-06-15 08:57:20 +02:00