From 85dc06662e77a7e1a61300888ecf2af5ff29e4c3 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 22 Aug 2012 11:44:20 +0200 Subject: [PATCH] simplify ProString::operator==() implementations we can trivially construct a QStringRef from a ProString, so take advantage of that. Change-Id: I9aaa1f6d910590872b250a145f16e90984beeb94 Reviewed-by: Daniel Teske --- src/shared/proparser/proitems.cpp | 33 ------------------------------- src/shared/proparser/proitems.h | 8 +++++--- 2 files changed, 5 insertions(+), 36 deletions(-) diff --git a/src/shared/proparser/proitems.cpp b/src/shared/proparser/proitems.cpp index 962268ca7da..1b16ded4d58 100644 --- a/src/shared/proparser/proitems.cpp +++ b/src/shared/proparser/proitems.cpp @@ -155,39 +155,6 @@ QString &ProString::toQString(QString &tmp) const return tmp.setRawData(m_string.constData() + m_offset, m_length); } -bool ProString::operator==(const ProString &other) const -{ - if (m_length != other.m_length) - return false; - return !memcmp(m_string.constData() + m_offset, - other.m_string.constData() + other.m_offset, m_length * 2); -} - -bool ProString::operator==(const QString &other) const -{ - if (m_length != other.length()) - return false; - return !memcmp(m_string.constData() + m_offset, other.constData(), m_length * 2); -} - -bool ProString::operator==(const QLatin1String &other) const -{ - const ushort *uc = (ushort *)m_string.constData() + m_offset; - const ushort *e = uc + m_length; - const uchar *c = (uchar *)other.latin1(); - - if (!c) - return isEmpty(); - - while (*c) { - if (uc == e || *uc != *c) - return false; - ++uc; - ++c; - } - return (uc == e); -} - QChar *ProString::prepareAppend(int extraLen) { if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) { diff --git a/src/shared/proparser/proitems.h b/src/shared/proparser/proitems.h index 52cd76a371b..fd48bb4eb00 100644 --- a/src/shared/proparser/proitems.h +++ b/src/shared/proparser/proitems.h @@ -78,9 +78,9 @@ public: ProString &operator+=(const ProString &other); ProString &append(const ProString &other, bool *pending = 0); ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false); - bool operator==(const ProString &other) const; - bool operator==(const QString &other) const; - bool operator==(const QLatin1String &other) const; + bool operator==(const ProString &other) const { return toQStringRef() == other.toQStringRef(); } + bool operator==(const QString &other) const { return toQStringRef() == other; } + bool operator==(const QLatin1String &other) const { return toQStringRef() == other; } bool operator!=(const ProString &other) const { return !(*this == other); } bool operator!=(const QString &other) const { return !(*this == other); } bool operator!=(const QLatin1String &other) const { return !(*this == other); } @@ -96,6 +96,8 @@ public: static uint hash(const QChar *p, int n); + ALWAYS_INLINE QStringRef toQStringRef() const { return QStringRef(&m_string, m_offset, m_length); } + ALWAYS_INLINE ProKey &toKey() { return *(ProKey *)this; } ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; }