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>
This commit is contained in:
parent
5e24d22af0
commit
c2293c897c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user