From 902120c62146e06db953a30cb876ecc7a5be3e28 Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 4 May 2020 15:08:09 +0200 Subject: Rhi: improve qHash implementations Use the combiners and an algorithm. Change-Id: I577950bbd2e8b0556f28e2a8381e432c22bb0dc9 Reviewed-by: Marc Mutz Reviewed-by: Laszlo Agocs --- src/gui/rhi/qshader.cpp | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'src/gui/rhi/qshader.cpp') diff --git a/src/gui/rhi/qshader.cpp b/src/gui/rhi/qshader.cpp index 18d0fdef05..2c1b333259 100644 --- a/src/gui/rhi/qshader.cpp +++ b/src/gui/rhi/qshader.cpp @@ -545,10 +545,12 @@ bool operator==(const QShader &lhs, const QShader &rhs) Q_DECL_NOTHROW */ size_t qHash(const QShader &s, size_t seed) Q_DECL_NOTHROW { - size_t h = s.stage(); - for (auto it = s.d->shaders.constBegin(), itEnd = s.d->shaders.constEnd(); it != itEnd; ++it) - h += qHash(it.key(), seed) + qHash(it.value().shader(), seed); - return h; + QtPrivate::QHashCombine hash; + seed = hash(seed, s.stage()); + seed = qHashRange(s.d->shaders.keyValueBegin(), + s.d->shaders.keyValueEnd(), + seed); + return seed; } /*! @@ -598,7 +600,11 @@ bool operator==(const QShaderKey &lhs, const QShaderKey &rhs) Q_DECL_NOTHROW */ size_t qHash(const QShaderKey &k, size_t seed) Q_DECL_NOTHROW { - return seed + 10 * k.source() + k.sourceVersion().version() + k.sourceVersion().flags() + k.sourceVariant(); + return qHashMulti(seed, + k.source(), + k.sourceVersion().version(), + k.sourceVersion().flags(), + k.sourceVariant()); } /*! @@ -620,6 +626,16 @@ bool operator==(const QShaderCode &lhs, const QShaderCode &rhs) Q_DECL_NOTHROW \relates QShaderCode */ +/*! + Returns the hash value for \a k, using \a seed to seed the calculation. + + \relates QShaderCode + */ +size_t qHash(const QShaderCode &k, size_t seed) noexcept +{ + return qHash(k.shader(), seed); +} + #ifndef QT_NO_DEBUG_STREAM QDebug operator<<(QDebug dbg, const QShader &bs) { -- cgit v1.2.3