diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-04-21 07:43:42 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-06-15 23:25:00 +0000 |
commit | bc144312c18e7436275267ad8900fce980597c45 (patch) | |
tree | a6a46e5b9d60d1b51577cc9dae2a256fa3c2662c | |
parent | 2a1122f46587e27f3d93e1f2af63f439116569c4 (diff) |
qHash: pass QByteArrayView to qHash() by value
The QBAV one should pass the parameter by value, like QStringView. And
now that we have it, the non-View one should call the View one in an
inline function, like we already do for QString.
The extra, defaulted parameter is there only so we get a different
signature in the new inline function compared to the removed one.
Pick-to: 6.4
Change-Id: If05aeeb7176e4f13af9afffd16e7f08062b1dc86
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
-rw-r--r-- | src/corelib/compat/removed_api.cpp | 12 | ||||
-rw-r--r-- | src/corelib/tools/qhash.cpp | 7 | ||||
-rw-r--r-- | src/corelib/tools/qhashfunctions.h | 8 |
3 files changed, 21 insertions, 6 deletions
diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 7c3dbd3be2..2b00142954 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -170,6 +170,18 @@ QCalendar::QCalendar(QLatin1StringView name) : QCalendar(QAnyStringView{name}) {} +#include "qhashfunctions.h" + +size_t qHash(const QByteArray &key, size_t seed) noexcept +{ + return qHashBits(key.constData(), size_t(key.size()), seed); +} + +size_t qHash(const QByteArrayView &key, size_t seed) noexcept +{ + return qHashBits(key.constData(), size_t(key.size()), seed); +} + #include "qobject.h" void QObject::setObjectName(const QString &name) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index c973eaeabe..2d9b6750c2 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -957,12 +957,7 @@ size_t qHashBits(const void *p, size_t size, size_t seed) noexcept return siphash(reinterpret_cast<const uchar *>(p), size, seed, seed2); } -size_t qHash(const QByteArray &key, size_t seed) noexcept -{ - return qHashBits(key.constData(), size_t(key.size()), seed); -} - -size_t qHash(const QByteArrayView &key, size_t seed) noexcept +size_t qHash(QByteArrayView key, size_t seed) noexcept { return qHashBits(key.constData(), size_t(key.size()), seed); } diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h index 04d165983d..58f4afc94f 100644 --- a/src/corelib/tools/qhashfunctions.h +++ b/src/corelib/tools/qhashfunctions.h @@ -144,8 +144,16 @@ Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(std::nullptr_t, size_t seed // (some) Qt types Q_DECL_CONST_FUNCTION constexpr inline size_t qHash(const QChar key, size_t seed = 0) noexcept { return qHash(key.unicode(), seed); } + +#if QT_CORE_REMOVED_SINCE(6, 4) Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0) noexcept; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(const QByteArrayView &key, size_t seed = 0) noexcept; +#else +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QByteArrayView key, size_t seed = 0) noexcept; +inline Q_DECL_PURE_FUNCTION size_t qHash(const QByteArray &key, size_t seed = 0 QT6_ONLY(, int = 0)) noexcept +{ return qHash(qToByteArrayViewIgnoringNull(key), seed); } +#endif + Q_CORE_EXPORT Q_DECL_PURE_FUNCTION size_t qHash(QStringView key, size_t seed = 0) noexcept; #if QT_STRINGVIEW_LEVEL < 2 inline Q_DECL_PURE_FUNCTION size_t qHash(const QString &key, size_t seed = 0) noexcept |