OSDN Git Service

use CRC-32 checksum for normalized types cache key
authorIvailo Monev <xakepa10@laimg.moc>
Mon, 17 Jun 2019 23:56:52 +0000 (23:56 +0000)
committerIvailo Monev <xakepa10@laimg.moc>
Mon, 17 Jun 2019 23:56:52 +0000 (23:56 +0000)
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
src/core/kernel/qmetaobject_p.h
src/core/tools/qbytearray.cpp

index 55c3c6f..9b2a8b2 100644 (file)
 #  include <QtCore/qobject_p.h>
 #endif
 
+#ifndef QT_NO_COMPRESS
+#  include <zlib.h>
+#endif
+
 QT_BEGIN_NAMESPACE
 
 enum PropertyFlags  {
@@ -170,18 +174,28 @@ static const optionalkeywords optional[] = {
 };
 static const int optionalkeywordssize = 3;
 
-typedef QHash<quint16, QByteArray> QNormalizedTypeHash;
+#ifndef QT_NO_COMPRESS
+static inline quint32 qCRC32(const char *data, uint len)
+{
+    quint32 crc_32 = ::crc32(0, 0, 0);
+    return ::crc32(crc_32, reinterpret_cast<const uchar *>(data), len);
+}
+
+typedef QHash<quint32, QByteArray> QNormalizedTypeHash;
 Q_GLOBAL_STATIC(QNormalizedTypeHash, qGlobalNormalizedTypeHash);
+#endif
 
 // This code is shared with moc.cpp
 static inline QByteArray normalizeTypeInternal(const char *t, const char *e)
 {
     int len = e - t;
-    quint16 cachekey = qChecksum(t, len);
+#ifndef QT_NO_COMPRESS
+    quint32 cachekey = qCRC32(t, len);
     QByteArray cached = qGlobalNormalizedTypeHash()->value(cachekey);
     if (!cached.isEmpty()) {
         return cached;
     }
+#endif
 
     /*
       Convert 'char const *' into 'const char *'. Start at index 1,
@@ -258,7 +272,9 @@ static inline QByteArray normalizeTypeInternal(const char *t, const char *e)
         result += *t++;
     }
 
+#ifndef QT_NO_COMPRESS
     qGlobalNormalizedTypeHash()->insert(cachekey, result);
+#endif
 
     return result;
 }
index b1cbc0c..31a3a19 100644 (file)
@@ -370,7 +370,6 @@ static const quint16 crc_tbl[16] = {
     \note This function is a 16-bit cache conserving (16 entry table)
     implementation of the CRC-16-CCITT algorithm.
 */
-
 quint16 qChecksum(const char *data, uint len)
 {
     quint16 crc = 0xffff;