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 <daniel.teske@nokia.com>
This commit is contained in:
Oswald Buddenhagen
2012-08-22 11:44:20 +02:00
parent d97de7e43f
commit 85dc06662e
2 changed files with 5 additions and 36 deletions

View File

@@ -155,39 +155,6 @@ QString &ProString::toQString(QString &tmp) const
return tmp.setRawData(m_string.constData() + m_offset, m_length); 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) QChar *ProString::prepareAppend(int extraLen)
{ {
if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) { if (m_string.isDetached() && m_length + extraLen <= m_string.capacity()) {

View File

@@ -78,9 +78,9 @@ public:
ProString &operator+=(const ProString &other); ProString &operator+=(const ProString &other);
ProString &append(const ProString &other, bool *pending = 0); ProString &append(const ProString &other, bool *pending = 0);
ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false); ProString &append(const ProStringList &other, bool *pending = 0, bool skipEmpty1st = false);
bool operator==(const ProString &other) const; bool operator==(const ProString &other) const { return toQStringRef() == other.toQStringRef(); }
bool operator==(const QString &other) const; bool operator==(const QString &other) const { return toQStringRef() == other; }
bool operator==(const QLatin1String &other) const; bool operator==(const QLatin1String &other) const { return toQStringRef() == other; }
bool operator!=(const ProString &other) const { return !(*this == other); } bool operator!=(const ProString &other) const { return !(*this == other); }
bool operator!=(const QString &other) const { return !(*this == other); } bool operator!=(const QString &other) const { return !(*this == other); }
bool operator!=(const QLatin1String &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); 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 ProKey &toKey() { return *(ProKey *)this; }
ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; } ALWAYS_INLINE const ProKey &toKey() const { return *(const ProKey *)this; }