Get rid of QHashedV4String
authorLars Knoll <lars.knoll@digia.com>
Wed, 26 Jun 2013 07:43:45 +0000 (09:43 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Jun 2013 12:56:04 +0000 (14:56 +0200)
This was required while we were using V8, but now
we can simply pass QV4::String pointers.

Change-Id: If6338e4a455d6132fe14e5e603e4fe9e477d1ffb
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
15 files changed:
src/qml/qml/ftw/qhashedstring_p.h
src/qml/qml/qqmlcontextwrapper.cpp
src/qml/qml/qqmlintegercache_p.h
src/qml/qml/qqmlmetatype.cpp
src/qml/qml/qqmlmetatype_p.h
src/qml/qml/qqmlpropertycache.cpp
src/qml/qml/qqmlpropertycache_p.h
src/qml/qml/qqmltypenamecache.cpp
src/qml/qml/qqmltypenamecache_p.h
src/qml/qml/qqmltypewrapper.cpp
src/qml/qml/qqmlvaluetypewrapper.cpp
src/qml/qml/v4/qv4qobjectwrapper.cpp
src/qml/qml/v4/qv4string_p.h
src/qml/types/qqmllistmodel.cpp
src/qml/types/qqmllistmodel_p_p.h

index efcee0f..4815f78 100644 (file)
@@ -98,27 +98,6 @@ private:
     mutable quint32 m_hash;
 };
 
-class Q_AUTOTEST_EXPORT QHashedV4String
-{
-public:
-    inline QHashedV4String();
-    explicit inline QHashedV4String(const QV4::Value &s);
-    inline QHashedV4String(const QHashedV4String &string);
-    inline QHashedV4String &operator=(const QHashedV4String &other);
-
-    inline bool operator==(const QHashedV4String &string);
-
-    inline quint32 hash() const;
-    inline int length() const; 
-
-    inline QV4::Value string() const;
-
-    inline QString toString() const;
-
-private:
-    QV4::Value m_string;
-};
-
 class QHashedCStringRef;
 class Q_AUTOTEST_EXPORT QHashedStringRef 
 {
@@ -267,9 +246,17 @@ public:
         }
     }
 
-    inline bool equals(const QHashedV4String &string) const {
-        return length == string.length() && hash == string.hash() && 
-               equals(string.string());
+    inline bool equals(const QV4::String *string) const {
+        if (length != string->length() || hash != string->hashValue())
+                return false;
+        if (isQString()) {
+            QStringDataPtr dd;
+            dd.ptr = strData;
+            strData->ref.ref();
+            return QString(dd) == string->toQString();
+        } else {
+            return QLatin1String(cStrData(), length) == string->toQString();
+        }
     }
 
     inline bool equals(const QHashedStringRef &string) const {
@@ -326,7 +313,8 @@ struct HashedForm {};
 template<> struct HashedForm<QString> { typedef QHashedString Type; };
 template<> struct HashedForm<QStringRef> { typedef QHashedStringRef Type; };
 template<> struct HashedForm<QHashedString> { typedef const QHashedString &Type; };
-template<> struct HashedForm<QHashedV4String> { typedef const QHashedV4String &Type; };
+template<> struct HashedForm<QV4::String *> { typedef const QV4::String *Type; };
+template<> struct HashedForm<const QV4::String *> { typedef const QV4::String *Type; };
 template<> struct HashedForm<QHashedStringRef> { typedef const QHashedStringRef &Type; };
 template<> struct HashedForm<QLatin1String> { typedef QHashedCStringRef Type; };
 template<> struct HashedForm<QHashedCStringRef> { typedef const QHashedCStringRef &Type; };
@@ -337,7 +325,8 @@ public:
     static HashedForm<QString>::Type hashedString(const QString &s) { return QHashedString(s);}
     static HashedForm<QStringRef>::Type hashedString(const QStringRef &s) { return QHashedStringRef(s.constData(), s.size());}
     static HashedForm<QHashedString>::Type hashedString(const QHashedString &s) { return s; }
-    static HashedForm<QHashedV4String>::Type hashedString(const QHashedV4String &s) { return s; }
+    static HashedForm<QV4::String *>::Type hashedString(QV4::String *s) { return s; }
+    static HashedForm<const QV4::String *>::Type hashedString(const QV4::String *s) { return s; }
     static HashedForm<QHashedStringRef>::Type hashedString(const QHashedStringRef &s) { return s; }
 
     static HashedForm<QLatin1String>::Type hashedString(const QLatin1String &s) { return QHashedCStringRef(s.data(), s.size()); }
@@ -345,14 +334,15 @@ public:
 
     static const QString &toQString(const QString &s) { return s; }
     static const QString &toQString(const QHashedString &s) { return s; }
-    static QString toQString(const QHashedV4String &s) { return s.toString(); }
+    static QString toQString(const QV4::String *s) { return s->toQString(); }
     static QString toQString(const QHashedStringRef &s) { return s.toString(); }
 
     static QString toQString(const QLatin1String &s) { return QString(s); }
     static QString toQString(const QHashedCStringRef &s) { return s.toUtf16(); }
 
     static inline quint32 hashOf(const QHashedStringRef &s) { return s.hash(); }
-    static inline quint32 hashOf(const QHashedV4String &s) { return s.hash(); }
+    static inline quint32 hashOf(QV4::String *s) { return s->hashValue(); }
+    static inline quint32 hashOf(const QV4::String *s) { return s->hashValue(); }
 
     template<typename K>
     static inline quint32 hashOf(const K &key) { return hashedString(key).hash(); }
@@ -464,7 +454,7 @@ public:
     template<typename K>
     inline T *value(const K &) const;
 
-    inline T *value(const QHashedV4String &string) const;
+    inline T *value(const QV4::String *string) const;
     inline T *value(const ConstIterator &) const;
 
     template<typename K>
@@ -873,7 +863,7 @@ T *QStringHash<T>::value(const ConstIterator &iter) const
 }
 
 template<class T>
-T *QStringHash<T>::value(const QHashedV4String &string) const
+T *QStringHash<T>::value(const QV4::String *string) const
 {
     Node *n = findNode(string);
     return n?&n->value:0;
@@ -1099,52 +1089,6 @@ quint32 QHashedString::existingHash() const
     return m_hash;
 }
 
-QHashedV4String::QHashedV4String()
-{
-}
-
-QHashedV4String::QHashedV4String(const QV4::Value &s)
-    : m_string(s)
-{
-    Q_ASSERT(s.isString());
-}
-
-QHashedV4String::QHashedV4String(const QHashedV4String &string)
-    : m_string(string.m_string)
-{
-}
-
-QHashedV4String &QHashedV4String::operator=(const QHashedV4String &other)
-{
-    m_string = other.m_string;
-    return *this;
-}
-
-bool QHashedV4String::operator==(const QHashedV4String &string)
-{
-    return m_string.asString()->isEqualTo(string.m_string.asString());
-}
-
-quint32 QHashedV4String::hash() const
-{
-    return m_string.asString()->hashValue();
-}
-
-int QHashedV4String::length() const
-{
-    return m_string.asString()->toQString().length();
-}
-
-QV4::Value QHashedV4String::string() const
-{
-    return m_string;
-}
-
-QString QHashedV4String::toString() const
-{
-    return m_string.toQString();
-}
-
 QHashedStringRef::QHashedStringRef() 
 : m_data(0), m_length(0), m_hash(0)
 {
index 6a3fd15..60345f6 100644 (file)
@@ -170,11 +170,9 @@ Value QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
 
     QObject *scopeObject = resource->getScopeObject();
 
-    QHashedV4String propertystring(Value::fromString(name));
-
     if (context->imports && name->startsWithUpper()) {
         // Search for attached properties, enums and imported scripts
-        QQmlTypeNameCache::Result r = context->imports->query(propertystring);
+        QQmlTypeNameCache::Result r = context->imports->query(name);
 
         if (r.isValid()) {
             if (hasProperty)
@@ -201,7 +199,7 @@ Value QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
     while (context) {
         // Search context properties
         if (context->propertyNames) {
-            int propertyIdx = context->propertyNames->value(propertystring);
+            int propertyIdx = context->propertyNames->value(name);
 
             if (propertyIdx != -1) {
 
@@ -302,11 +300,9 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
 
     QObject *scopeObject = wrapper->getScopeObject();
 
-    QHashedV4String propertystring(Value::fromString(name));
-
     while (context) {
         // Search context properties
-        if (context->propertyNames && -1 != context->propertyNames->value(propertystring))
+        if (context->propertyNames && -1 != context->propertyNames->value(name))
             return;
 
         // Search scope object
index 5fe4039..98b57af 100644 (file)
@@ -71,7 +71,7 @@ public:
     void reserve(int);
 
     int value(const QString &);
-    inline int value(const QHashedV4String &);
+    inline int value(const QV4::String *);
 
     QString findId(int value) const;
 
@@ -80,7 +80,7 @@ private:
     StringCache stringCache;
 };
 
-int QQmlIntegerCache::value(const QHashedV4String &name)
+int QQmlIntegerCache::value(const QV4::String *name)
 {
     int *result = stringCache.value(name);
     return result?*result:-1;
index 9a9e6df..188fa7d 100644 (file)
@@ -902,7 +902,7 @@ int QQmlType::enumValue(const QHashedCStringRef &name, bool *ok) const
     return -1;
 }
 
-int QQmlType::enumValue(const QHashedV4String &name, bool *ok) const
+int QQmlType::enumValue(const QV4::String *name, bool *ok) const
 {
     Q_ASSERT(ok);
     *ok = true;
@@ -976,7 +976,7 @@ QQmlType *QQmlTypeModule::type(const QHashedStringRef &name, int minor)
     return 0;
 }
 
-QQmlType *QQmlTypeModule::type(const QHashedV4String &name, int minor)
+QQmlType *QQmlTypeModule::type(const QV4::String *name, int minor)
 {
     QReadLocker lock(metaTypeDataLock());
 
@@ -1045,7 +1045,7 @@ QQmlType *QQmlTypeModuleVersion::type(const QHashedStringRef &name) const
     else return 0;
 }
 
-QQmlType *QQmlTypeModuleVersion::type(const QHashedV4String &name) const
+QQmlType *QQmlTypeModuleVersion::type(const QV4::String *name) const
 {
     if (m_module) return m_module->type(name, m_minor);
     else return 0;
index 26fba2b..e44eade 100644 (file)
@@ -61,6 +61,8 @@
 #include <QtCore/qbitarray.h>
 #include <QtQml/qjsvalue.h>
 
+#include <private/qv4string_p.h>
+
 QT_BEGIN_NAMESPACE
 
 class QQmlType;
@@ -136,7 +138,6 @@ private:
 
 struct QQmlMetaTypeData;
 class QHashedCStringRef;
-class QHashedV4String;
 class Q_QML_PRIVATE_EXPORT QQmlType
 {
 public:
@@ -213,7 +214,7 @@ public:
 
     int enumValue(const QHashedStringRef &, bool *ok) const;
     int enumValue(const QHashedCStringRef &, bool *ok) const;
-    int enumValue(const QHashedV4String &, bool *ok) const;
+    int enumValue(const QV4::String *, bool *ok) const;
 private:
     QQmlType *superType() const;
     friend class QQmlTypePrivate;
@@ -252,7 +253,7 @@ public:
     int maximumMinorVersion() const;
 
     QQmlType *type(const QHashedStringRef &, int);
-    QQmlType *type(const QHashedV4String &, int);
+    QQmlType *type(const QV4::String *, int);
 
     QList<QQmlType*> singletonTypes(int) const;
 
@@ -279,7 +280,7 @@ public:
     int minorVersion() const;
 
     QQmlType *type(const QHashedStringRef &) const;
-    QQmlType *type(const QHashedV4String &) const;
+    QQmlType *type(const QV4::String *) const;
 
 private:
     QQmlTypeModule *m_module;
index 08005f1..65406c9 100644 (file)
@@ -1376,14 +1376,14 @@ inline const QString &qQmlPropertyCacheToString(const QString &string)
     return string;
 }
 
-inline QString qQmlPropertyCacheToString(const QHashedV4String &string)
+inline QString qQmlPropertyCacheToString(const QV4::String *string)
 {
-    return string.toString();
+    return string->toQString();
 }
 
 template<typename T>
 QQmlPropertyData *
-qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj, const T &name,
+qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj, name,
                           QQmlContextData *context, QQmlPropertyData &local)
 {
     QQmlPropertyCache *cache = 0;
@@ -1417,17 +1417,17 @@ qQmlPropertyCacheProperty(QQmlEngine *engine, QObject *obj, const T &name,
 }
 
 QQmlPropertyData *
-QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj, const QHashedV4String &name,
+QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj, const QV4::String *name,
                             QQmlContextData *context, QQmlPropertyData &local)
 {
-    return qQmlPropertyCacheProperty<QHashedV4String>(engine, obj, name, context, local);
+    return qQmlPropertyCacheProperty<const QV4::String *>(engine, obj, name, context, local);
 }
 
 QQmlPropertyData *
 QQmlPropertyCache::property(QQmlEngine *engine, QObject *obj,
                                     const QString &name, QQmlContextData *context, QQmlPropertyData &local)
 {
-    return qQmlPropertyCacheProperty<QString>(engine, obj, name, context, local);
+    return qQmlPropertyCacheProperty<const QString &>(engine, obj, name, context, local);
 }
 
 static inline const QMetaObjectPrivate *priv(const uint* data)
index 737b39c..7bc7c46 100644 (file)
@@ -304,7 +304,7 @@ public:
     inline QQmlEngine *qmlEngine() const;
     static QQmlPropertyData *property(QQmlEngine *, QObject *, const QString &,
                                               QQmlContextData *, QQmlPropertyData &);
-    static QQmlPropertyData *property(QQmlEngine *, QObject *, const QHashedV4String &,
+    static QQmlPropertyData *property(QQmlEngine *, QObject *, const QV4::String *,
                                               QQmlContextData *, QQmlPropertyData &);
     static int *methodParameterTypes(QObject *, int index, QVarLengthArray<int, 9> &dummy,
                                      QByteArray *unknownTypeError);
index 8c522c2..38466aa 100644 (file)
@@ -91,7 +91,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedStringRef &name,
     return typeSearch(i->modules, name);
 }
 
-QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV4String &name)
+QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name)
 {
     Result result = query(m_namedImports, name);
 
@@ -101,7 +101,7 @@ QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV4String &name)
     return result;
 }
 
-QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QHashedV4String &name, const void *importNamespace)
+QQmlTypeNameCache::Result QQmlTypeNameCache::query(const QV4::String *name, const void *importNamespace)
 {
     Q_ASSERT(importNamespace);
     const Import *i = static_cast<const Import *>(importNamespace);
index 33c0121..094bd5c 100644 (file)
@@ -90,8 +90,8 @@ public:
     };
     Result query(const QHashedStringRef &);
     Result query(const QHashedStringRef &, const void *importNamespace);
-    Result query(const QHashedV4String &);
-    Result query(const QHashedV4String &, const void *importNamespace);
+    Result query(const QV4::String *);
+    Result query(const QV4::String *, const void *importNamespace);
 
 private:
     friend class QQmlImports;
index 241d1f4..f4e9d9b 100644 (file)
@@ -129,8 +129,6 @@ Value QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
 
     QObject *object = w->object;
 
-    QHashedV4String propertystring(Value::fromString(name));
-
     if (w->type) {
         QQmlType *type = w->type;
 
@@ -174,7 +172,7 @@ Value QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
 
             if (name->startsWithUpper()) {
                 bool ok = false;
-                int value = type->enumValue(propertystring, &ok);
+                int value = type->enumValue(name, &ok);
                 if (ok)
                     return QV4::Value::fromInt32(value);
 
@@ -195,7 +193,7 @@ Value QmlTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
 
     } else if (w->typeNamespace) {
         Q_ASSERT(w->importNamespace);
-        QQmlTypeNameCache::Result r = w->typeNamespace->query(propertystring,
+        QQmlTypeNameCache::Result r = w->typeNamespace->query(name,
                                                                              w->importNamespace);
 
         if (r.isValid()) {
@@ -236,8 +234,6 @@ void QmlTypeWrapper::put(Managed *m, String *name, const Value &value)
     QV8Engine *v8engine = v4->v8Engine;
     QQmlContextData *context = v8engine->callingContext();
 
-    QHashedV4String propertystring(Value::fromString(name));
-
     QQmlType *type = w->type;
     if (type && !type->isSingleton() && w->object) {
         QObject *object = w->object;
index 388025d..7355e0d 100644 (file)
@@ -251,8 +251,6 @@ Value QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
     if (!r)
         v4->current->throwTypeError();
 
-    QHashedV4String propertystring(Value::fromString(name));
-
     // Note: readReferenceValue() can change the reference->type.
     if (r->objectType == QmlValueTypeWrapper::Reference) {
         QmlValueTypeReference *reference = static_cast<QmlValueTypeReference *>(r);
@@ -273,9 +271,9 @@ Value QmlValueTypeWrapper::get(Managed *m, String *name, bool *hasProperty)
     {
         QQmlData *ddata = QQmlData::get(r->type, false);
         if (ddata && ddata->propertyCache)
-            result = ddata->propertyCache->property(propertystring, 0, 0);
+            result = ddata->propertyCache->property(name, 0, 0);
         else
-            result = QQmlPropertyCache::property(r->v8->engine(), r->type, propertystring, 0, local);
+            result = QQmlPropertyCache::property(r->v8->engine(), r->type, name, 0, local);
     }
 
     if (!result)
index a267c4a..92fa220 100644 (file)
@@ -261,16 +261,14 @@ void QObjectWrapper::initializeBindings(ExecutionEngine *engine)
 
 QQmlPropertyData *QObjectWrapper::findProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, QQmlPropertyData *local) const
 {
-    QHashedV4String propertystring(QV4::Value::fromString(name));
-
     QQmlData *ddata = QQmlData::get(m_object, false);
     if (!ddata)
         return 0;
     QQmlPropertyData *result = 0;
     if (ddata && ddata->propertyCache)
-        result = ddata->propertyCache->property(propertystring, m_object, qmlContext);
+        result = ddata->propertyCache->property(name, m_object, qmlContext);
     if (!result)
-        result = QQmlPropertyCache::property(engine->v8Engine->engine(), m_object, propertystring, qmlContext, *local);
+        result = QQmlPropertyCache::property(engine->v8Engine->engine(), m_object, name, qmlContext, *local);
     return result;
 }
 
@@ -297,8 +295,7 @@ Value QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextData *qml
         if (includeImports && name->startsWithUpper()) {
             // Check for attached properties
             if (qmlContext && qmlContext->imports) {
-                QHashedV4String propertystring(QV4::Value::fromString(name));
-                QQmlTypeNameCache::Result r = qmlContext->imports->query(propertystring);
+                QQmlTypeNameCache::Result r = qmlContext->imports->query(name);
 
                 if (hasProperty)
                     *hasProperty = true;
@@ -418,8 +415,7 @@ bool QObjectWrapper::setQmlProperty(ExecutionContext *ctx, QQmlContextData *qmlC
     QQmlPropertyData local;
     QQmlPropertyData *result = 0;
     {
-        QHashedV4String property(Value::fromString(name));
-        result = QQmlPropertyCache::property(ctx->engine->v8Engine->engine(), object, property, qmlContext, local);
+        result = QQmlPropertyCache::property(ctx->engine->v8Engine->engine(), object, name, qmlContext, local);
     }
 
     if (!result)
index 205bcec..81108c6 100644 (file)
@@ -113,6 +113,9 @@ struct Q_QML_EXPORT String : public Managed {
     bool startsWithUpper() const {
         return _text.length() && _text.at(0).isUpper();
     }
+    int length() const {
+        return _text.length();
+    }
 
     QString _text;
     mutable uint stringHash;
index 5091e46..f371429 100644 (file)
@@ -104,10 +104,9 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(const QString &key, Role::Da
     return createRole(key, type);
 }
 
-const ListLayout::Role &ListLayout::getRoleOrCreate(const QV4::Value &key, Role::DataType type)
+const ListLayout::Role &ListLayout::getRoleOrCreate(const QV4::String *key, Role::DataType type)
 {
-    QHashedV4String hashedKey(key);
-    QStringHash<Role *>::Node *node = roleHash.findNode(hashedKey);
+    QStringHash<Role *>::Node *node = roleHash.findNode(key);
     if (node) {
         const Role &r = *node->value;
         if (type != r.type)
@@ -115,7 +114,7 @@ const ListLayout::Role &ListLayout::getRoleOrCreate(const QV4::Value &key, Role:
         return r;
     }
 
-    QString qkey = key.toQString();
+    QString qkey = key->toQString();
 
     return createRole(qkey, type);
 }
@@ -240,11 +239,10 @@ const ListLayout::Role *ListLayout::getExistingRole(const QString &key)
     return r;
 }
 
-const ListLayout::Role *ListLayout::getExistingRole(const QV4::Value &key)
+const ListLayout::Role *ListLayout::getExistingRole(const QV4::String *key)
 {
     Role *r = 0;
-    QHashedV4String hashedKey(key);
-    QStringHash<Role *>::Node *node = roleHash.findNode(hashedKey);
+    QStringHash<Role *>::Node *node = roleHash.findNode(key);
     if (node)
         r = node->value;
     return r;
@@ -419,8 +417,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, QVector<int> *roles,
     QV4::ObjectIterator it(object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly);
     while (1) {
         QV4::Value propertyValue;
-        QV4::Value propertyName = it.nextPropertyNameAsString(&propertyValue);
-        if (propertyName.isNull())
+        QV4::String *propertyName = it.nextPropertyNameAsString(&propertyValue).asString();
+        if (!propertyName)
             break;
 
         // Check if this key exists yet
@@ -485,8 +483,8 @@ void ListModel::set(int elementIndex, QV4::Object *object, QV8Engine *eng)
     QV4::ObjectIterator it(object, QV4::ObjectIterator::WithProtoChain|QV4::ObjectIterator::EnumerableOnly);
     while (1) {
         QV4::Value propertyValue;
-        QV4::Value propertyName = it.nextPropertyNameAsString(&propertyValue);
-        if (propertyName.isNull())
+        QV4::String *propertyName = it.nextPropertyNameAsString(&propertyValue).asString();
+        if (!propertyName)
             break;
 
         // Add the value now
index 48cd248..de083a9 100644 (file)
@@ -209,12 +209,12 @@ public:
     };
 
     const Role *getRoleOrCreate(const QString &key, const QVariant &data);
-    const Role &getRoleOrCreate(const QV4::Value &key, Role::DataType type);
+    const Role &getRoleOrCreate(const QV4::String *key, Role::DataType type);
     const Role &getRoleOrCreate(const QString &key, Role::DataType type);
 
     const Role &getExistingRole(int index) { return *roles.at(index); }
     const Role *getExistingRole(const QString &key);
-    const Role *getExistingRole(const QV4::Value &key);
+    const Role *getExistingRole(const QV4::String *key);
 
     int roleCount() const { return roles.count(); }