From 8d44bb2c5431d0278e80b13fb796e71622d22e4b Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 29 Mar 2017 18:16:09 +0200 Subject: [PATCH] Add qHash(QStringView) [ChangeLog][QtCore] Added qHash(QStringView). Change-Id: I69c9203cf301fe586e924168381884aab2e19e5c Reviewed-by: Olivier Goffart (Woboq GmbH) Reviewed-by: Anton Kudryavtsev --- src/corelib/tools/qhash.cpp | 14 ++++++++++++++ src/corelib/tools/qhashfunctions.h | 5 ++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 2d974145775..f83643e90a0 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -235,6 +235,7 @@ uint qHash(const QByteArray &key, uint seed) Q_DECL_NOTHROW return hash(reinterpret_cast(key.constData()), size_t(key.size()), seed); } +#if QT_STRINGVIEW_LEVEL < 2 uint qHash(const QString &key, uint seed) Q_DECL_NOTHROW { return hash(key.unicode(), size_t(key.size()), seed); @@ -244,6 +245,12 @@ uint qHash(const QStringRef &key, uint seed) Q_DECL_NOTHROW { return hash(key.unicode(), size_t(key.size()), seed); } +#endif + +uint qHash(QStringView key, uint seed) Q_DECL_NOTHROW +{ + return hash(key.data(), key.size(), seed); +} uint qHash(const QBitArray &bitArray, uint seed) Q_DECL_NOTHROW { @@ -1023,6 +1030,13 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW Returns the hash value for the \a key, using \a seed to seed the calculation. */ +/*! \fn uint qHash(QStringView key, uint seed = 0) + \relates QStringView + \since 5.10 + + Returns the hash value for the \a key, using \a seed to seed the calculation. +*/ + /*! \fn uint qHash(QLatin1String key, uint seed = 0) \relates QHash \since 5.0 diff --git a/src/corelib/tools/qhashfunctions.h b/src/corelib/tools/qhashfunctions.h index 6c271208235..2c3abe6af0b 100644 --- a/src/corelib/tools/qhashfunctions.h +++ b/src/corelib/tools/qhashfunctions.h @@ -41,7 +41,7 @@ #ifndef QHASHFUNCTIONS_H #define QHASHFUNCTIONS_H -#include +#include #include #include // for std::accumulate @@ -95,8 +95,11 @@ Q_CORE_EXPORT Q_DECL_CONST_FUNCTION uint qHash(long double key, uint seed = 0) Q #endif Q_DECL_CONST_FUNCTION Q_DECL_CONSTEXPR inline uint qHash(const QChar key, uint seed = 0) Q_DECL_NOTHROW { return qHash(key.unicode(), seed); } Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QByteArray &key, uint seed = 0) Q_DECL_NOTHROW; +#if QT_STRINGVIEW_LEVEL < 2 Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QString &key, uint seed = 0) Q_DECL_NOTHROW; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QStringRef &key, uint seed = 0) Q_DECL_NOTHROW; +#endif +Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QStringView key, uint seed = 0) Q_DECL_NOTHROW; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(const QBitArray &key, uint seed = 0) Q_DECL_NOTHROW; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qHash(QLatin1String key, uint seed = 0) Q_DECL_NOTHROW; Q_CORE_EXPORT Q_DECL_PURE_FUNCTION uint qt_hash(QStringView key) Q_DECL_NOTHROW;