Get rid of QQmlIntegerCache
authorLars Knoll <lars.knoll@digia.com>
Thu, 27 Jun 2013 14:47:06 +0000 (16:47 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Fri, 28 Jun 2013 12:56:20 +0000 (14:56 +0200)
Replace by the new IdentifierIntHash.

Change-Id: Ib210cd898a30ad3e2f9349387e1a74d92ed5f831
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/qml/qml/qml.pri
src/qml/qml/qqmlcompileddata.cpp
src/qml/qml/qqmlcompiler.cpp
src/qml/qml/qqmlcompiler_p.h
src/qml/qml/qqmlcontext.cpp
src/qml/qml/qqmlcontext_p.h
src/qml/qml/qqmlcontextwrapper.cpp
src/qml/qml/qqmlintegercache.cpp [deleted file]
src/qml/qml/qqmlintegercache_p.h [deleted file]

index 31904f8..658b1f8 100644 (file)
@@ -31,7 +31,6 @@ SOURCES += \
     $$PWD/qqmlcleanup.cpp \
     $$PWD/qqmlpropertycache.cpp \
     $$PWD/qqmlnotifier.cpp \
-    $$PWD/qqmlintegercache.cpp \
     $$PWD/qqmltypenotavailable.cpp \
     $$PWD/qqmltypenamecache.cpp \
     $$PWD/qqmlscriptstring.cpp \
@@ -104,7 +103,6 @@ HEADERS += \
     $$PWD/qqmlcleanup_p.h \
     $$PWD/qqmlpropertycache_p.h \
     $$PWD/qqmlnotifier_p.h \
-    $$PWD/qqmlintegercache_p.h \
     $$PWD/qqmltypenotavailable_p.h \
     $$PWD/qqmltypenamecache_p.h \
     $$PWD/qqmlscriptstring.h \
index d44ae16..abe278f 100644 (file)
@@ -119,9 +119,6 @@ QQmlCompiledData::~QQmlCompiledData()
     for (int ii = 0; ii < propertyCaches.count(); ++ii) 
         propertyCaches.at(ii)->release();
 
-    for (int ii = 0; ii < contextCaches.count(); ++ii)
-        contextCaches.at(ii)->release();
-
     for (int ii = 0; ii < scripts.count(); ++ii)
         scripts.at(ii)->release();
 
index dcc33a2..55212e5 100644 (file)
@@ -3554,10 +3554,10 @@ int QQmlCompiler::genContextCache()
     if (compileState->ids.count() == 0)
         return -1;
 
-    QQmlIntegerCache *cache = new QQmlIntegerCache();
-    cache->reserve(compileState->ids.count());
+    QV4::IdentifierIntHash cache(QV8Engine::getV4(engine->handle()));
+    cache.reserve(compileState->ids.count());
     for (Object *o = compileState->ids.first(); o; o = compileState->ids.next(o)) 
-        cache->add(o->id, o->idIndex);
+        cache.add(o->id, o->idIndex);
 
     output->contextCaches.append(cache);
     return output->contextCaches.count() - 1;
index c866638..55e055e 100644 (file)
@@ -60,9 +60,9 @@
 #include "qqmlengine_p.h"
 #include <private/qbitfield_p.h>
 #include "qqmlpropertycache_p.h"
-#include "qqmlintegercache_p.h"
 #include "qqmltypenamecache_p.h"
 #include "qqmltypeloader_p.h"
+#include "private/qv4identifier_p.h"
 
 #include <QtCore/qbytearray.h>
 #include <QtCore/qset.h>
@@ -121,7 +121,7 @@ public:
     QList<QByteArray> datas;
     QByteArray bytecode;
     QList<QQmlPropertyCache *> propertyCaches;
-    QList<QQmlIntegerCache *> contextCaches;
+    QList<QV4::IdentifierIntHash> contextCaches;
     QList<QQmlScriptData *> scripts;
     QList<QUrl> urls;
 
index daa115b..684ac9e 100644 (file)
@@ -312,11 +312,12 @@ void QQmlContext::setContextProperty(const QString &name, const QVariant &value)
         }
     }
 
-    if (!data->propertyNames) data->propertyNames = new QQmlIntegerCache();
+    if (data->propertyNames.isEmpty())
+        data->propertyNames = QV4::IdentifierIntHash(QV8Engine::getV4(engine()->handle()));
 
-    int idx = data->propertyNames->value(name);
+    int idx = data->propertyNames.value(name);
     if (idx == -1) {
-        data->propertyNames->add(name, data->idValueCount + d->propertyValues.count());
+        data->propertyNames.add(name, data->idValueCount + d->propertyValues.count());
         d->propertyValues.append(value);
 
         data->refreshExpressions();
@@ -349,11 +350,12 @@ void QQmlContext::setContextProperty(const QString &name, QObject *value)
         return;
     }
 
-    if (!data->propertyNames) data->propertyNames = new QQmlIntegerCache();
-    int idx = data->propertyNames->value(name);
+    if (data->propertyNames.isEmpty())
+        data->propertyNames = QV4::IdentifierIntHash(QV8Engine::getV4(engine()->handle()));
+    int idx = data->propertyNames.value(name);
 
     if (idx == -1) {
-        data->propertyNames->add(name, data->idValueCount + d->propertyValues.count());
+        data->propertyNames.add(name, data->idValueCount + d->propertyValues.count());
         d->propertyValues.append(QVariant::fromValue(value));
 
         data->refreshExpressions();
@@ -375,8 +377,8 @@ QVariant QQmlContext::contextProperty(const QString &name) const
 
     QQmlContextData *data = d->data;
 
-    if (data->propertyNames)
-        idx = data->propertyNames->value(name);
+    if (data->propertyNames.count())
+        idx = data->propertyNames.value(name);
 
     if (idx == -1) {
         QByteArray utf8Name = name.toUtf8();
@@ -522,7 +524,7 @@ QQmlContextData::QQmlContextData()
 : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), 
   isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), isRootObjectInCreation(false),
   publicContext(0), activeVMEData(0),
-  propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+  contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
   expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0),
   componentAttached(0)
 {
@@ -532,7 +534,7 @@ QQmlContextData::QQmlContextData(QQmlContext *ctxt)
 : parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), 
   isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), isRootObjectInCreation(false),
   publicContext(ctxt), activeVMEData(0),
-  propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+  contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
   expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), linkedContext(0),
   componentAttached(0)
 {
@@ -636,9 +638,6 @@ void QQmlContextData::destroy()
     }
     contextGuards = 0;
 
-    if (propertyNames)
-        propertyNames->release();
-
     if (imports)
         imports->release();
 
@@ -771,31 +770,30 @@ void QQmlContextData::setIdProperty(int idx, QObject *obj)
     idValues[idx].context = this;
 }
 
-void QQmlContextData::setIdPropertyData(QQmlIntegerCache *data)
+void QQmlContextData::setIdPropertyData(const QV4::IdentifierIntHash &data)
 {
-    Q_ASSERT(!propertyNames);
+    Q_ASSERT(propertyNames.isEmpty());
     propertyNames = data;
-    propertyNames->addref();
 
-    idValueCount = data->count();
+    idValueCount = data.count();
     idValues = new ContextGuard[idValueCount];
 }
 
 QString QQmlContextData::findObjectId(const QObject *obj) const
 {
-    if (!propertyNames)
+    if (propertyNames.isEmpty())
         return QString();
 
     for (int ii = 0; ii < idValueCount; ii++) {
         if (idValues[ii] == obj)
-            return propertyNames->findId(ii);
+            return propertyNames.findId(ii);
     }
 
     if (publicContext) {
         QQmlContextPrivate *p = QQmlContextPrivate::get(publicContext);
         for (int ii = 0; ii < p->propertyValues.count(); ++ii)
             if (p->propertyValues.at(ii) == QVariant::fromValue((QObject *)obj))
-                return propertyNames->findId(ii);
+                return propertyNames.findId(ii);
     }
 
     if (linkedContext)
index 0a0720a..9fd9a10 100644 (file)
@@ -56,7 +56,6 @@
 #include "qqmlcontext.h"
 
 #include "qqmldata_p.h"
-#include "qqmlintegercache_p.h"
 #include "qqmltypenamecache_p.h"
 #include "qqmlnotifier_p.h"
 #include "qqmllist.h"
@@ -70,6 +69,7 @@
 #include <private/qflagpointer_p.h>
 #include <private/qqmlguard_p.h>
 
+#include <private/qv4identifier_p.h>
 
 QT_BEGIN_NAMESPACE
 
@@ -152,7 +152,7 @@ public:
     void *activeVMEData;
 
     // Property name cache
-    QQmlIntegerCache *propertyNames;
+    QV4::IdentifierIntHash propertyNames;
 
     // Context object
     QObject *contextObject;
@@ -198,7 +198,7 @@ public:
     ContextGuard *idValues;
     int idValueCount;
     void setIdProperty(int, QObject *);
-    void setIdPropertyData(QQmlIntegerCache *);
+    void setIdPropertyData(const QV4::IdentifierIntHash &);
 
     // Linked contexts. this owns linkedContext.
     QQmlContextData *linkedContext;
index 60345f6..4a66c75 100644 (file)
@@ -198,8 +198,8 @@ Value QmlContextWrapper::get(Managed *m, String *name, bool *hasProperty)
 
     while (context) {
         // Search context properties
-        if (context->propertyNames) {
-            int propertyIdx = context->propertyNames->value(name);
+        if (context->propertyNames.count()) {
+            int propertyIdx = context->propertyNames.value(name);
 
             if (propertyIdx != -1) {
 
@@ -302,7 +302,7 @@ void QmlContextWrapper::put(Managed *m, String *name, const Value &value)
 
     while (context) {
         // Search context properties
-        if (context->propertyNames && -1 != context->propertyNames->value(name))
+        if (context->propertyNames.count() && -1 != context->propertyNames.value(name))
             return;
 
         // Search scope object
diff --git a/src/qml/qml/qqmlintegercache.cpp b/src/qml/qml/qqmlintegercache.cpp
deleted file mode 100644 (file)
index 3b44c3d..0000000
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia.  For licensing terms and
-** conditions see http://qt.digia.com/licensing.  For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights.  These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include "qqmlintegercache_p.h"
-
-QT_BEGIN_NAMESPACE
-
-QQmlIntegerCache::QQmlIntegerCache()
-{
-}
-
-QQmlIntegerCache::~QQmlIntegerCache()
-{
-}
-
-QString QQmlIntegerCache::findId(int value) const
-{
-    for (StringCache::ConstIterator iter = stringCache.begin();
-            iter != stringCache.end(); ++iter) {
-        if (iter.value() == value)
-            return iter.key();
-    }
-    return QString();
-}
-
-void QQmlIntegerCache::reserve(int size)
-{ 
-    stringCache.reserve(size);
-}
-
-void QQmlIntegerCache::add(const QString &id, int value)
-{
-    Q_ASSERT(!stringCache.contains(id));
-
-    stringCache.insert(id, value);
-}
-
-int QQmlIntegerCache::value(const QString &id)
-{
-    int *rv = stringCache.value(id);
-    return rv?*rv:-1;
-}
-
-QT_END_NAMESPACE
diff --git a/src/qml/qml/qqmlintegercache_p.h b/src/qml/qml/qqmlintegercache_p.h
deleted file mode 100644 (file)
index 98b57af..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
-** Contact: http://www.qt-project.org/legal
-**
-** This file is part of the QtQml module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and Digia.  For licensing terms and
-** conditions see http://qt.digia.com/licensing.  For further information
-** use the contact form at http://qt.digia.com/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Digia gives you certain additional
-** rights.  These rights are described in the Digia Qt LGPL Exception
-** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file.  Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QQMLINTEGERCACHE_P_H
-#define QQMLINTEGERCACHE_P_H
-
-//
-//  W A R N I N G
-//  -------------
-//
-// This file is not part of the Qt API.  It exists purely as an
-// implementation detail.  This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#include <private/qqmlrefcount_p.h>
-#include <private/qhashedstring_p.h>
-
-QT_BEGIN_NAMESPACE
-
-class QQmlType;
-class QQmlEngine;
-class QQmlIntegerCache : public QQmlRefCount
-{
-public:
-    QQmlIntegerCache();
-    virtual ~QQmlIntegerCache();
-
-    inline int count() const;
-    void add(const QString &, int);
-    void reserve(int);
-
-    int value(const QString &);
-    inline int value(const QV4::String *);
-
-    QString findId(int value) const;
-
-private:
-    typedef QStringHash<int> StringCache;
-    StringCache stringCache;
-};
-
-int QQmlIntegerCache::value(const QV4::String *name)
-{
-    int *result = stringCache.value(name);
-    return result?*result:-1;
-}
-
-int QQmlIntegerCache::count() const 
-{
-    return stringCache.count();
-}
-
-QT_END_NAMESPACE
-
-#endif // QQMLINTEGERCACHE_P_H
-