Improve qHash(QFont)
When the families member was added to QFontDef, it was included in op== and qHash(), however the seed was passed to two qHash() calls for subobjects. With xor used as the combiner, it could happen that the seed was xored out (e.g. on empty strings), leaving a slight opening for prediciable hash values. Fix by using QtPrivate::QHashCombine, which handles the seed in such a way as to avoid the issue. Change-Id: I8a3e4c2f368306446554249763695158df5ac634 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
fbb2ed1505
commit
5ef6e1fa54
@ -138,19 +138,20 @@ struct QFontDef
|
||||
|
||||
inline uint qHash(const QFontDef &fd, uint seed = 0) noexcept
|
||||
{
|
||||
return qHash(qRound64(fd.pixelSize*10000)) // use only 4 fractional digits
|
||||
^ qHash(fd.weight)
|
||||
^ qHash(fd.style)
|
||||
^ qHash(fd.stretch)
|
||||
^ qHash(fd.styleHint)
|
||||
^ qHash(fd.styleStrategy)
|
||||
^ qHash(fd.ignorePitch)
|
||||
^ qHash(fd.fixedPitch)
|
||||
^ qHash(fd.family, seed)
|
||||
^ qHash(fd.families, seed)
|
||||
^ qHash(fd.styleName)
|
||||
^ qHash(fd.hintingPreference)
|
||||
;
|
||||
QtPrivate::QHashCombine hash;
|
||||
seed = hash(seed, qRound64(fd.pixelSize*10000)); // use only 4 fractional digits
|
||||
seed = hash(seed, fd.weight);
|
||||
seed = hash(seed, fd.style);
|
||||
seed = hash(seed, fd.stretch);
|
||||
seed = hash(seed, fd.styleHint);
|
||||
seed = hash(seed, fd.styleStrategy);
|
||||
seed = hash(seed, fd.ignorePitch);
|
||||
seed = hash(seed, fd.fixedPitch);
|
||||
seed = hash(seed, fd.family);
|
||||
seed = hash(seed, fd.families);
|
||||
seed = hash(seed, fd.styleName);
|
||||
seed = hash(seed, fd.hintingPreference);
|
||||
return seed;
|
||||
}
|
||||
|
||||
class QFontEngineData
|
||||
|
Loading…
Reference in New Issue
Block a user