From 1629deec839552fb78689c8edd93a3ffab61efde Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 2 Sep 2014 11:02:20 +0200 Subject: QTextFormat: use qHash(double/float) instead of own implementation The implementation of hash(float) does not treat +0 and -0 the same, thus violating the property required of hash functions that they produce equal hash values for equal input. Simply use the qHash() FP functions which recently became available and which do not have that problem. This was found by unrelated code review. I'm not aware of any user- visible issue this fixes. Change-Id: I458c384aaf112e29cea677022969b62a34263cfb Reviewed-by: Lars Knoll Reviewed-by: Konstantin Ritt --- src/gui/text/qtextformat.cpp | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'src/gui/text/qtextformat.cpp') diff --git a/src/gui/text/qtextformat.cpp b/src/gui/text/qtextformat.cpp index 4854af0d01..0bb60516b5 100644 --- a/src/gui/text/qtextformat.cpp +++ b/src/gui/text/qtextformat.cpp @@ -266,20 +266,6 @@ private: friend QDataStream &operator>>(QDataStream &, QTextFormat &); }; -// this is only safe because sizeof(int) == sizeof(float) -static inline uint hash(float d) -{ -#ifdef Q_CC_GNU - // this is a GCC extension and isn't guaranteed to work in other compilers - // the reinterpret_cast below generates a strict-aliasing warning with GCC - union { float f; uint u; } cvt; - cvt.f = d; - return cvt.u; -#else - return reinterpret_cast(d); -#endif -} - static inline uint hash(const QColor &color) { return (color.isValid()) ? color.rgba() : 0x234109; @@ -287,7 +273,7 @@ static inline uint hash(const QColor &color) static inline uint hash(const QPen &pen) { - return hash(pen.color()) + hash(pen.widthF()); + return hash(pen.color()) + qHash(pen.widthF()); } static inline uint hash(const QBrush &brush) @@ -300,7 +286,7 @@ static inline uint variantHash(const QVariant &variant) // simple and fast hash functions to differentiate between type and value switch (variant.userType()) { // sorted by occurrence frequency case QVariant::String: return qHash(variant.toString()); - case QVariant::Double: return hash(variant.toDouble()); + case QVariant::Double: return qHash(variant.toDouble()); case QVariant::Int: return 0x811890 + variant.toInt(); case QVariant::Brush: return 0x01010101 + hash(qvariant_cast(variant)); @@ -311,7 +297,7 @@ static inline uint variantHash(const QVariant &variant) case QVariant::Color: return hash(qvariant_cast(variant)); case QVariant::TextLength: return 0x377 + hash(qvariant_cast(variant).rawValue()); - case QMetaType::Float: return hash(variant.toFloat()); + case QMetaType::Float: return qHash(variant.toFloat()); case QVariant::Invalid: return 0; default: break; } -- cgit v1.2.3