summaryrefslogtreecommitdiffstats
path: root/src/gui/text/qtextformat.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2014-09-02 11:02:20 +0200
committerMarc Mutz <marc.mutz@kdab.com>2014-09-02 19:07:08 +0200
commit1629deec839552fb78689c8edd93a3ffab61efde (patch)
treefac7e671872fa9aa75f4d31997b3b72213ffff93 /src/gui/text/qtextformat.cpp
parent23c1b132b1727caee1a4891c34ef27e3a5697df5 (diff)
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 <lars.knoll@digia.com> Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
Diffstat (limited to 'src/gui/text/qtextformat.cpp')
-rw-r--r--src/gui/text/qtextformat.cpp20
1 files changed, 3 insertions, 17 deletions
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<uint&>(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<QBrush>(variant));
@@ -311,7 +297,7 @@ static inline uint variantHash(const QVariant &variant)
case QVariant::Color: return hash(qvariant_cast<QColor>(variant));
case QVariant::TextLength:
return 0x377 + hash(qvariant_cast<QTextLength>(variant).rawValue());
- case QMetaType::Float: return hash(variant.toFloat());
+ case QMetaType::Float: return qHash(variant.toFloat());
case QVariant::Invalid: return 0;
default: break;
}