diff options
| author | Marc Mutz <marc.mutz@qt.io> | 2025-11-16 23:00:04 +0100 |
|---|---|---|
| committer | Marc Mutz <marc.mutz@qt.io> | 2025-12-09 08:40:42 +0000 |
| commit | f9e25bbbb4e99941e3a4fef0cb2e64c1b6451d12 (patch) | |
| tree | 4d97b45b9303910081b0f2de469f4029d4f91370 /src/qmlcompiler/qqmljsannotation.cpp | |
| parent | 11f9fe51ab0536ca33368fbf4ebb01194da6a4d2 (diff) | |
QQmlJSAnnotation: de-inline op== and qHash()
Way too much is going on in these functions to have them as
inlines. Presumably, op== "looked" simple (but QHash equality is
anything but...), and qHash() was inline because of the defaulted seed
argument. Use overloading instead.
The type doesn't seem to be used outside its own module, so there's no
need to export the out-of-line functions.
Amends d226e24a5d4288a3e7f263c526cb6cbf72255388.
Pick-to: 6.11 6.10 6.8 6.5
Change-Id: Ib9641001a590fd1482ec463afd48003b7759e2f8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsannotation.cpp')
| -rw-r--r-- | src/qmlcompiler/qqmljsannotation.cpp | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljsannotation.cpp b/src/qmlcompiler/qqmljsannotation.cpp index 7d3f3a6bc4..76fc275be6 100644 --- a/src/qmlcompiler/qqmljsannotation.cpp +++ b/src/qmlcompiler/qqmljsannotation.cpp @@ -23,4 +23,37 @@ QQQmlJSDeprecation QQmlJSAnnotation::deprecation() const { return deprecation; } +// hidden friend +bool operator==(const QQmlJSAnnotation &a, const QQmlJSAnnotation &b) noexcept +{ + return a.name == b.name && + a.bindings == b.bindings; +} + +// hidden friend +size_t qHash(const QQmlJSAnnotation &annotation, size_t seed) noexcept +{ + QtPrivate::QHashCombine combine(seed); + seed = combine(seed, annotation.name); + + for (auto it = annotation.bindings.constBegin(); it != annotation.bindings.constEnd(); ++it) { + size_t h = combine(seed, it.key()); + // use + to keep the result independent of the ordering of the keys + + const auto &var = it.value(); + + if (var.valueless_by_exception()) + continue; + + if (auto v = get_if<double>(&var)) + seed += combine(h, *v); + else if (auto v = get_if<QString>(&var)) + seed += combine(h, *v); + else + Q_UNREACHABLE(); + } + + return seed; +} + QT_END_NAMESPACE |
