summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoraavit <qt_aavit@ovi.com>2012-05-22 10:59:17 +0200
committerQt by Nokia <qt-info@nokia.com>2012-05-23 14:21:47 +0200
commitb5a11a7be5ca30405d4bb7125fe56c121bf0acf8 (patch)
tree4bc4ad2804408aabc917f7c2242c415c49c8017f
parentf604fd8ff482e03353283f90f9089e64c036a2dc (diff)
Allow QHash randomization to be disabled by environment variable
The new randomization of QHash is enabled by default. There may be cases where you need deterministic behavior, e.g. for debugging or regression testing. This patch disables randomization if QT_HASH_SEED is defined. Change-Id: Idfad55ea7aba830add0a36334f0f763c62fdce13 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
-rw-r--r--src/corelib/tools/qhash.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/corelib/tools/qhash.cpp b/src/corelib/tools/qhash.cpp
index 3172014363..cc8f5beca5 100644
--- a/src/corelib/tools/qhash.cpp
+++ b/src/corelib/tools/qhash.cpp
@@ -158,6 +158,10 @@ uint qHash(const QLatin1String &key, uint seed)
*/
static uint qt_create_qhash_seed()
{
+ QByteArray envSeed = qgetenv("QT_HASH_SEED");
+ if (!envSeed.isNull())
+ return envSeed.toUInt();
+
uint seed = 0;
#ifdef Q_OS_UNIX
@@ -866,6 +870,13 @@ void QHashData::checkSanity()
process, and then passed by QHash as the second argument of the
two-arguments overload of the qHash() function.
+ This randomization of QHash is enabled by default. Even though programs
+ should never depend on a particular QHash ordering, there may be situations
+ where you temporarily need deterministic behavior, e.g. for debugging or
+ regression testing. To disable the randomization, define the environment
+ variable \c QT_HASH_SEED. The contents of that variable, interpreted as a
+ decimal value, will be used as the seed for qHash().
+
\sa QHashIterator, QMutableHashIterator, QMap, QSet
*/