diff options
author | Lars Knoll <lars.knoll@digia.com> | 2013-06-27 16:47:06 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-06-28 14:56:20 +0200 |
commit | 7259642e35fc8a1d354697f8b1700cbadd540870 (patch) | |
tree | 72253c00d19777677007eae052af1f1b5b0c186b /src/qml | |
parent | f418bbb8836a648bdd08728e88323a4c8db9140c (diff) |
Get rid of QQmlIntegerCache
Replace by the new IdentifierIntHash.
Change-Id: Ib210cd898a30ad3e2f9349387e1a74d92ed5f831
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml')
-rw-r--r-- | src/qml/qml/qml.pri | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcompileddata.cpp | 3 | ||||
-rw-r--r-- | src/qml/qml/qqmlcompiler.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/qqmlcompiler_p.h | 4 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 38 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext_p.h | 6 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontextwrapper.cpp | 6 | ||||
-rw-r--r-- | src/qml/qml/qqmlintegercache.cpp | 82 | ||||
-rw-r--r-- | src/qml/qml/qqmlintegercache_p.h | 97 |
9 files changed, 29 insertions, 215 deletions
diff --git a/src/qml/qml/qml.pri b/src/qml/qml/qml.pri index 31904f81e2..658b1f8f85 100644 --- a/src/qml/qml/qml.pri +++ b/src/qml/qml/qml.pri @@ -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 \ diff --git a/src/qml/qml/qqmlcompileddata.cpp b/src/qml/qml/qqmlcompileddata.cpp index d44ae16fd2..abe278f570 100644 --- a/src/qml/qml/qqmlcompileddata.cpp +++ b/src/qml/qml/qqmlcompileddata.cpp @@ -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(); diff --git a/src/qml/qml/qqmlcompiler.cpp b/src/qml/qml/qqmlcompiler.cpp index dcc33a20a3..55212e5d6c 100644 --- a/src/qml/qml/qqmlcompiler.cpp +++ b/src/qml/qml/qqmlcompiler.cpp @@ -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; diff --git a/src/qml/qml/qqmlcompiler_p.h b/src/qml/qml/qqmlcompiler_p.h index c866638650..55e055e182 100644 --- a/src/qml/qml/qqmlcompiler_p.h +++ b/src/qml/qml/qqmlcompiler_p.h @@ -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; diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index daa115b952..684ac9e980 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -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) diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h index 0a0720a99d..9fd9a107bc 100644 --- a/src/qml/qml/qqmlcontext_p.h +++ b/src/qml/qml/qqmlcontext_p.h @@ -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; diff --git a/src/qml/qml/qqmlcontextwrapper.cpp b/src/qml/qml/qqmlcontextwrapper.cpp index 60345f6626..4a66c7552d 100644 --- a/src/qml/qml/qqmlcontextwrapper.cpp +++ b/src/qml/qml/qqmlcontextwrapper.cpp @@ -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 index 3b44c3dc37..0000000000 --- a/src/qml/qml/qqmlintegercache.cpp +++ /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 index 98b57af279..0000000000 --- a/src/qml/qml/qqmlintegercache_p.h +++ /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 - |