Commit 85dc0666 authored by Oswald Buddenhagen's avatar Oswald Buddenhagen
Browse files

simplify ProString::operator==() implementations



we can trivially construct a QStringRef from a ProString, so take
advantage of that.

Change-Id: I9aaa1f6d910590872b250a145f16e90984beeb94
Reviewed-by: default avatarDaniel Teske <daniel.teske@nokia.com>
parent d97de7e4
......@@ -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()) {
......
......@@ -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; }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment