effectively revert facd387374

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2024-06-03 18:05:49 +03:00
parent 0655cbc3ed
commit ab7932ad04
4 changed files with 62 additions and 17 deletions

View file

@ -35,7 +35,9 @@
#include <string.h>
#include <stdlib.h>
#include <libdeflate.h>
#ifndef QT_BOOTSTRAPPED
# include <libdeflate.h>
#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

View file

@ -23,14 +23,37 @@
#include "qbitarray.h"
#include "qstring.h"
#include <libdeflate.h>
#include <stdlib.h>
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,

View file

@ -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<const char *>(key.unicode()), key.size() * sizeof(QChar));
}
inline uint qHash(const QStringRef &key)
{
return qHash(reinterpret_cast<const char *>(key.unicode()), key.size() * sizeof(QChar));
}
template <class T> inline uint qHash(const T *key)
{
return qHash(reinterpret_cast<quintptr>(key));

View file

@ -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})