diff options
Diffstat (limited to 'src/corelib/tools/qhash.cpp')
-rw-r--r-- | src/corelib/tools/qhash.cpp | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp index 7200ea7993..8e4f0f6407 100644 --- a/src/corelib/tools/qhash.cpp +++ b/src/corelib/tools/qhash.cpp @@ -94,13 +94,14 @@ QT_BEGIN_NAMESPACE (for instance, gcc 4.4 does that even at -O0). */ -#ifdef __SSE4_2__ +#if QT_COMPILER_SUPPORTS_HERE(SSE4_2) static inline bool hasFastCrc32() { - return true; + return qCpuHasFeature(SSE4_2); } template <typename Char> +QT_FUNCTION_TARGET(SSE4_2) static uint crc32(const Char *ptr, size_t len, uint h) { // The CRC32 instructions from Nehalem calculate a 32-bit CRC32 checksum @@ -163,6 +164,11 @@ static inline uint hash(const uchar *p, int len, uint seed) Q_DECL_NOTHROW return h; } +uint qHashBits(const void *p, size_t len, uint seed) Q_DECL_NOTHROW +{ + return hash(static_cast<const uchar*>(p), int(len), seed); +} + static inline uint hash(const QChar *p, int len, uint seed) Q_DECL_NOTHROW { uint h = seed; @@ -669,6 +675,25 @@ void QHashData::checkSanity() Types \c T1 and \c T2 must be supported by qHash(). */ +/*! \fn uint qHashBits(const void *p, size_t len, uint seed = 0) + \relates QHash + \since 5.4 + + Returns the hash value for the memory block of size \a len pointed + to by \a p, using \a seed to seed the calculation. + + Use this function only to implement qHash() for your own custom + types. E.g., here's how you could implement a qHash() overload for + std::vector<int>: + + \snippet code/src_corelib_tools_qhash.cpp qhashbits + + It bears repeating that the implementation of qHashBits() - like + the qHash() overloads offered by Qt - may change at any time. You + \b{must not} rely on the fact that qHashBits() will give the same + results (for the same inputs) across different Qt versions. +*/ + /*! \fn uint qHash(char key, uint seed = 0) \relates QHash \since 5.0 @@ -778,7 +803,7 @@ uint qHash(long double key, uint seed) Q_DECL_NOTHROW } #endif -/*! \fn uint qHash(QChar key, uint seed = 0) +/*! \fn uint qHash(const QChar key, uint seed = 0) \relates QHash \since 5.0 |