OSDN Git Service

QByteArray is not padded anymore thus simplify QBitArray hashing
authorIvailo Monev <xakepa10@laimg.moc>
Wed, 10 Jul 2019 22:51:46 +0000 (22:51 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Wed, 10 Jul 2019 22:51:46 +0000 (22:51 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
src/core/tools/qhash.cpp

index eb4184b..2a6d2bb 100644 (file)
@@ -94,15 +94,7 @@ uint qHash(const QStringRef &key)
 
 uint qHash(const QBitArray &bitArray)
 {
-    int m = bitArray.d.size() - 1;
-    uint result = hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), qMax(0, m));
-
-    // deal with the last 0 to 7 bits manually, because we can't trust that
-    // the padding is initialized to 0 in bitArray.d
-    int n = bitArray.size();
-    if (n & 0x7)
-        result = ((result << 4) + bitArray.d.at(m)) & ((1 << n) - 1);
-    return result;
+    return hash(reinterpret_cast<const uchar *>(bitArray.d.constData()), qMax(0, bitArray.d.size() - 1));
 }
 
 /*