From ab7932ad04c44cd94f1d3392ca661293ac08c1cd Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Mon, 3 Jun 2024 18:05:49 +0300 Subject: [PATCH] effectively revert facd387374612149bee85c0418e77cb02c595caa Signed-off-by: Ivailo Monev --- src/core/tools/qbytearray.cpp | 29 ++++++++++++++++++++++----- src/core/tools/qhash.cpp | 37 +++++++++++++++++++++++++++++++++-- src/core/tools/qhash.h | 10 ++-------- src/tools/moc/CMakeLists.txt | 3 +-- 4 files changed, 62 insertions(+), 17 deletions(-) diff --git a/src/core/tools/qbytearray.cpp b/src/core/tools/qbytearray.cpp index e02a0d736..125d83945 100644 --- a/src/core/tools/qbytearray.cpp +++ b/src/core/tools/qbytearray.cpp @@ -35,7 +35,9 @@ #include #include -#include +#ifndef QT_BOOTSTRAPPED +# include +#endif #define IS_RAW_DATA(d) ((d)->data != (d)->array) @@ -296,6 +298,7 @@ QByteArray qRandomUuid() */ QByteArray qCompress(const char* data, int nbytes, int compressionLevel) { +#ifndef QT_BOOTSTRAPPED if (Q_UNLIKELY(!data)) { qWarning("qCompress: Data is null"); return QByteArray(); @@ -328,6 +331,13 @@ QByteArray qCompress(const char* data, int nbytes, int compressionLevel) result.resize(compresult); return result; +#else + Q_UNUSED(data); + Q_UNUSED(nbytes); + Q_UNUSED(compressionLevel); + Q_ASSERT_X(false, "qCompress", "internal error"); + return QByteArray(); +#endif } /*! @@ -354,6 +364,7 @@ QByteArray qCompress(const char* data, int nbytes, int compressionLevel) */ QByteArray qUncompress(const char* data, int nbytes) { +#ifndef QT_BOOTSTRAPPED if (Q_UNLIKELY(!data)) { qWarning("qUncompress: Data is null"); return QByteArray(); @@ -402,12 +413,20 @@ QByteArray qUncompress(const char* data, int nbytes) } } return result; +#else + Q_UNUSED(data); + Q_UNUSED(nbytes); + Q_ASSERT_X(false, "qUncompress", "internal error"); + return QByteArray(); +#endif } -QByteArray::Data QByteArray::shared_null = { QAtomicInt(1), - 0, 0, shared_null.array, {0} }; -QByteArray::Data QByteArray::shared_empty = { QAtomicInt(1), - 0, 0, shared_empty.array, {0} }; +QByteArray::Data QByteArray::shared_null = { + QAtomicInt(1), 0, 0, shared_null.array, {0} +}; +QByteArray::Data QByteArray::shared_empty = { + QAtomicInt(1), 0, 0, shared_empty.array, {0} +}; /*! \class QByteArray diff --git a/src/core/tools/qhash.cpp b/src/core/tools/qhash.cpp index e5328c898..7f5f23963 100644 --- a/src/core/tools/qhash.cpp +++ b/src/core/tools/qhash.cpp @@ -23,14 +23,37 @@ #include "qbitarray.h" #include "qstring.h" -#include #include QT_BEGIN_NAMESPACE +/* + These functions are based on Peter J. Weinberger's hash function + (from the Dragon Book). The constant 24 in the original function + was replaced with 23 to produce fewer collisions on input such as + "a", "aa", "aaa", "aaaa", ... +*/ +static inline uint hash(const QChar *p, int n) +{ + uint h = 0; + while (n--) { + h = (h << 4) + (*p++).unicode(); + h ^= (h & 0xf0000000) >> 23; + h &= 0x0fffffff; + } + return h; +} + uint qHash(const char *key, const uint len) { - return libdeflate_crc32(0, key, len); + uint h = 0; + uint n = len; + while (n--) { + h = (h << 4) + *key++; + h ^= (h & 0xf0000000) >> 23; + h &= 0x0fffffff; + } + return h; } uint qHash(const QBitArray &bitArray) @@ -38,6 +61,16 @@ uint qHash(const QBitArray &bitArray) return qHash(bitArray.d.constData(), bitArray.d.size()); } +uint qHash(const QString &key) +{ + return hash(key.unicode(), key.size()); +} + +uint qHash(const QStringRef &key) +{ + return hash(key.unicode(), key.size()); +} + /* The prime_deltas array is a table of selected prime values, even though it doesn't look like one. The primes we are using are 1, diff --git a/src/core/tools/qhash.h b/src/core/tools/qhash.h index adeebd46c..ec1b48cfe 100644 --- a/src/core/tools/qhash.h +++ b/src/core/tools/qhash.h @@ -36,6 +36,8 @@ class QStringRef; Q_CORE_EXPORT uint qHash(const char *key, const uint len); Q_CORE_EXPORT uint qHash(const QBitArray &key); +Q_CORE_EXPORT uint qHash(const QString &key); +Q_CORE_EXPORT uint qHash(const QStringRef &key); inline uint qHash(const char key) { return uint(key); } inline uint qHash(const uchar key) { return uint(key); } @@ -64,14 +66,6 @@ inline uint qHash(const quint64 key) inline uint qHash(const qint64 key) { return qHash(quint64(key)); } inline uint qHash(const QChar key) { return qHash(key.unicode()); } inline uint qHash(const QByteArray &key) { return qHash(key.constData(), key.size()); } -inline uint qHash(const QString &key) -{ - return qHash(reinterpret_cast(key.unicode()), key.size() * sizeof(QChar)); -} -inline uint qHash(const QStringRef &key) -{ - return qHash(reinterpret_cast(key.unicode()), key.size() * sizeof(QChar)); -} template inline uint qHash(const T *key) { return qHash(reinterpret_cast(key)); diff --git a/src/tools/moc/CMakeLists.txt b/src/tools/moc/CMakeLists.txt index 1d89cb65b..15321d3eb 100644 --- a/src/tools/moc/CMakeLists.txt +++ b/src/tools/moc/CMakeLists.txt @@ -11,7 +11,6 @@ include_directories( ${CMAKE_BINARY_DIR}/include/QtCore ${CMAKE_CURRENT_SOURCE_DIR} ${ICU_INCLUDES} - ${DEFLATE_INCLUDES} ) set(MOC_SOURCES @@ -81,7 +80,7 @@ set(BOOTSTRAP_SOURCES add_executable(bootstrap_moc ${BOOTSTRAP_SOURCES} ${MOC_SOURCES}) target_compile_definitions(bootstrap_moc PRIVATE ${BOOTSTRAP_DEFINITIONS}) -target_link_libraries(bootstrap_moc ${ICU_LIBRARIES} ${DEFLATE_LIBRARIES}) +target_link_libraries(bootstrap_moc ${ICU_LIBRARIES}) add_executable(moc ${MOC_SOURCES}) target_link_libraries(moc ${EXTRA_MOC_LIBS})