Remove an overoptimisation that was only used (wrongly) in one place
authorLars Knoll <lars.knoll@digia.com>
Tue, 25 Jun 2013 19:53:06 +0000 (21:53 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Jun 2013 12:55:55 +0000 (14:55 +0200)
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>
src/qml/qml/ftw/qhashedstring.cpp
src/qml/qml/ftw/qhashedstring_p.h
src/qml/qml/qqmlimport.cpp

index 99f342f..0af68e8 100644 (file)
@@ -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)
index ca95839..1261db2 100644 (file)
@@ -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)
index 50b2c8a..816f9ce 100644 (file)
@@ -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,