summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2012-04-13 18:59:58 +0100
committerQt by Nokia <qt-info@nokia.com>2012-04-14 15:49:16 +0200
commitc2293c897c9f2e35dffec777c19577c0f6052e81 (patch)
treed64222df4200f01833bde36f41184f11ff19ce9f /src/corelib/tools
parent5e24d22af075ce790b471fb9aca59a80037f34df (diff)
QHash: remove optimization for QHash<int, T>
QHash employs an optimization for int/uints, squashing the hash value and the key value inside an union. This obviously works iff qHash(int k) = k. If the hash value gets salted, the hash table is corrupted. This patch removes that optimization by means of a #if 0, so if further research finds out that we want those 4 bytes back it's pretty simple to revert. Change-Id: If273f0bf2ff007f4f2f7c46d2aab364a3b455cf1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qhash.h15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/corelib/tools/qhash.h b/src/corelib/tools/qhash.h
index 1aa4fa7adc..e3188729c5 100644
--- a/src/corelib/tools/qhash.h
+++ b/src/corelib/tools/qhash.h
@@ -218,7 +218,19 @@ struct QHashNode
inline bool same_key(uint h0, const Key &key0) { return h0 == h && key0 == key; }
};
-
+#if 0
+// ###
+// The introduction of the QHash random seed breaks this optimization, as it
+// relies on qHash(int i) = i. If the hash value is salted, then the hash
+// table becomes corrupted.
+//
+// A bit more research about whether it makes sense or not to salt integer
+// keys (and in general keys whose hash value is easy to invert)
+// is needed, or about how keep this optimization and the seed (f.i. by
+// specializing QHash for integer values, and re-apply the seed during lookup).
+//
+// Be aware that such changes can easily be binary incompatible, and therefore
+// cannot be made during the Qt 5 lifetime.
#define Q_HASH_DECLARE_INT_NODES(key_type) \
template <class T> \
struct QHashDummyNode<key_type, T> { \
@@ -246,6 +258,7 @@ Q_HASH_DECLARE_INT_NODES(ushort);
Q_HASH_DECLARE_INT_NODES(int);
Q_HASH_DECLARE_INT_NODES(uint);
#undef Q_HASH_DECLARE_INT_NODES
+#endif // #if 0
template <class Key, class T>
class QHash