diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-06-25 21:53:06 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-28 14:55:55 +0200 |
commit | 4a3d5537dde71c57378da7e65e732d50f88e592a (patch) | |
tree | 066bd56f26a43b08478f17a5a10c716e5c6a811e /src | |
parent | dfbec73b35cc600be0614081a0ef280d53a1c79e (diff) |
Remove an overoptimisation that was only used (wrongly) in one place
Let's simplify this code. The goal is to replace most of the
code in qhashedstring with an identifier based hash table.
Change-Id: I2f9a38ad0bb2f43a2b2b87914823c23ed231f48c
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/qml/qml/ftw/qhashedstring.cpp | 35 | ||||
-rw-r--r-- | src/qml/qml/ftw/qhashedstring_p.h | 28 | ||||
-rw-r--r-- | src/qml/qml/qqmlimport.cpp | 2 |
3 files changed, 8 insertions, 57 deletions
diff --git a/src/qml/qml/ftw/qhashedstring.cpp b/src/qml/qml/ftw/qhashedstring.cpp index 99f342f6f0..0af68e89f6 100644 --- a/src/qml/qml/ftw/qhashedstring.cpp +++ b/src/qml/qml/ftw/qhashedstring.cpp @@ -341,14 +341,6 @@ static void utf8FromUtf16(char *output, const QChar *uc, int len) } } -void QHashedStringRef::computeUtf8Length() const -{ - if (m_length) - m_utf8length = utf8LengthFromUtf16(m_data, m_length); - else - m_utf8length = 0; -} - QHashedStringRef QHashedStringRef::mid(int offset, int length) const { Q_ASSERT(offset < m_length); @@ -396,33 +388,6 @@ QString QHashedStringRef::toString() const return QString(m_data, m_length); } -QByteArray QHashedStringRef::toUtf8() const -{ - if (m_length == 0) - return QByteArray(); - - QByteArray result; - result.resize(utf8length()); - writeUtf8(result.data()); - return result; -} - -void QHashedStringRef::writeUtf8(char *output) const -{ - if (m_length) { - int ulen = utf8length(); - if (ulen == m_length) { - // Must be a latin1 string - uchar *o = (uchar *)output; - const QChar *c = m_data; - while (ulen--) - *o++ = (uchar)((*c++).unicode()); - } else { - utf8FromUtf16(output, m_data, m_length); - } - } -} - QString QHashedCStringRef::toUtf16() const { if (m_length == 0) diff --git a/src/qml/qml/ftw/qhashedstring_p.h b/src/qml/qml/ftw/qhashedstring_p.h index ca95839323..1261db234d 100644 --- a/src/qml/qml/ftw/qhashedstring_p.h +++ b/src/qml/qml/ftw/qhashedstring_p.h @@ -160,18 +160,13 @@ public: inline bool isLatin1() const; - inline int utf8length() const; - QByteArray toUtf8() const; - void writeUtf8(char *) const; private: friend class QHashedString; void computeHash() const; - void computeUtf8Length() const; const QChar *m_data; int m_length; - mutable int m_utf8length; mutable quint32 m_hash; }; @@ -1180,38 +1175,37 @@ QString QHashedV4String::toString() const } QHashedStringRef::QHashedStringRef() -: m_data(0), m_length(0), m_utf8length(-1), m_hash(0) +: m_data(0), m_length(0), m_hash(0) { } QHashedStringRef::QHashedStringRef(const QString &str) -: m_data(str.constData()), m_length(str.length()), m_utf8length(0), m_hash(0) +: m_data(str.constData()), m_length(str.length()), m_hash(0) { } QHashedStringRef::QHashedStringRef(const QStringRef &str) -: m_data(str.constData()), m_length(str.length()), m_utf8length(0), m_hash(0) +: m_data(str.constData()), m_length(str.length()), m_hash(0) { } QHashedStringRef::QHashedStringRef(const QChar *data, int length) -: m_data(data), m_length(length), m_utf8length(0), m_hash(0) +: m_data(data), m_length(length), m_hash(0) { } QHashedStringRef::QHashedStringRef(const QChar *data, int length, quint32 hash) -: m_data(data), m_length(length), m_utf8length(0), m_hash(hash) +: m_data(data), m_length(length), m_hash(hash) { } QHashedStringRef::QHashedStringRef(const QHashedString &string) -: m_data(string.constData()), m_length(string.length()), m_utf8length(0), m_hash(string.m_hash) +: m_data(string.constData()), m_length(string.length()), m_hash(string.m_hash) { } QHashedStringRef::QHashedStringRef(const QHashedStringRef &string) -: m_data(string.m_data), m_length(string.m_length), m_utf8length(string.m_utf8length), - m_hash(string.m_hash) +: m_data(string.m_data), m_length(string.m_length), m_hash(string.m_hash) { } @@ -1219,7 +1213,6 @@ QHashedStringRef &QHashedStringRef::operator=(const QHashedStringRef &o) { m_data = o.m_data; m_length = o.m_length; - m_utf8length = o.m_utf8length; m_hash = o.m_hash; return *this; } @@ -1304,13 +1297,6 @@ int QHashedStringRef::length() const return m_length; } -int QHashedStringRef::utf8length() const -{ - if (m_utf8length < m_length) - computeUtf8Length(); - return m_utf8length; -} - bool QHashedStringRef::isLatin1() const { for (int ii = 0; ii < m_length; ++ii) diff --git a/src/qml/qml/qqmlimport.cpp b/src/qml/qml/qqmlimport.cpp index 50b2c8af0d..816f9cec0f 100644 --- a/src/qml/qml/qqmlimport.cpp +++ b/src/qml/qml/qqmlimport.cpp @@ -136,7 +136,7 @@ QQmlType *getTypeForUrl(const QString &urlString, const QHashedStringRef& typeNa QHashedStringRef unqualifiedtype = dot < 0 ? typeName : QHashedStringRef(typeName.constData() + dot + 1, typeName.length() - dot - 1); //XXX: The constData of the string ref is pointing somewhere unsafe in qmlregister, so we need to create a temporary copy - QByteArray buf(unqualifiedtype.toUtf8().constData()); + QByteArray buf(unqualifiedtype.toString().toUtf8()); QQmlPrivate::RegisterCompositeType reg = { url, |