diff options
Diffstat (limited to 'src/qml/qml/ftw/qhashedstring_p.h')
-rw-r--r-- | src/qml/qml/ftw/qhashedstring_p.h | 44 |
1 files changed, 21 insertions, 23 deletions
diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index c5353acdb1..8f0bd74c53 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -79,7 +79,6 @@ public: inline quint32 hash() const; inline quint32 existingHash() const; - static bool compare(const QChar *lhs, const QChar *rhs, int length); static inline bool compare(const QChar *lhs, const char *rhs, int length); static inline bool compare(const char *lhs, const char *rhs, int length); @@ -217,9 +216,10 @@ bool QHashedString::operator==(const QHashedString &string) const bool QHashedString::operator==(const QHashedStringRef &string) const { - return length() == string.m_length && - (string.m_hash == m_hash || !string.m_hash || !m_hash) && - QHashedString::compare(constData(), string.m_data, string.m_length); + if (m_hash && string.m_hash && m_hash != string.m_hash) + return false; + QStringView otherView {string.m_data, string.m_length}; + return static_cast<const QString &>(*this) == otherView; } quint32 QHashedString::hash() const @@ -277,22 +277,26 @@ QHashedStringRef &QHashedStringRef::operator=(const QHashedStringRef &o) bool QHashedStringRef::operator==(const QString &string) const { - return m_length == string.length() && - QHashedString::compare(string.constData(), m_data, m_length); + QStringView view {m_data, m_length}; + return view == string; } bool QHashedStringRef::operator==(const QHashedString &string) const { - return m_length == string.length() && - (m_hash == string.m_hash || !m_hash || !string.m_hash) && - QHashedString::compare(string.constData(), m_data, m_length); + if (m_hash && string.m_hash && m_hash != string.m_hash) + return false; + QStringView view {m_data, m_length}; + QStringView otherView {string.constData(), string.length()}; + return view == otherView; } bool QHashedStringRef::operator==(const QHashedStringRef &string) const { - return m_length == string.m_length && - (m_hash == string.m_hash || !m_hash || !string.m_hash) && - QHashedString::compare(string.m_data, m_data, m_length); + if (m_hash && string.m_hash && m_hash != string.m_hash) + return false; + QStringView view {m_data, m_length}; + QStringView otherView {string.m_data, string.m_length}; + return view == otherView; } bool QHashedStringRef::operator==(const QHashedCStringRef &string) const @@ -304,29 +308,22 @@ bool QHashedStringRef::operator==(const QHashedCStringRef &string) const bool QHashedStringRef::operator!=(const QString &string) const { - return m_length != string.length() || - !QHashedString::compare(string.constData(), m_data, m_length); + return !(*this == string); } bool QHashedStringRef::operator!=(const QHashedString &string) const { - return m_length != string.length() || - (m_hash != string.m_hash && m_hash && string.m_hash) || - !QHashedString::compare(string.constData(), m_data, m_length); + return !(*this == string); } bool QHashedStringRef::operator!=(const QHashedStringRef &string) const { - return m_length != string.m_length || - (m_hash != string.m_hash && m_hash && string.m_hash) || - QHashedString::compare(string.m_data, m_data, m_length); + return !(*this == string); } bool QHashedStringRef::operator!=(const QHashedCStringRef &string) const { - return m_length != string.m_length || - (m_hash != string.m_hash && m_hash && string.m_hash) || - QHashedString::compare(m_data, string.m_data, m_length); + return !(*this == string); } QChar *QHashedStringRef::data() @@ -452,6 +449,7 @@ bool QHashedString::compare(const char *lhs, const char *rhs, int length) return 0 == ::memcmp(lhs, rhs, length); } + quint32 QHashedString::stringHash(const QChar *data, int length) { return QV4::String::createHashValue(data, length, nullptr); |