aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-01-02 14:23:46 +0100
committerLars Knoll <lars.knoll@qt.io>2018-01-10 07:53:26 +0000
commitebf024a136b5d9950c0b17ce64363bd23be2f637 (patch)
tree7014afc7cdc9b33a7511cf582676a0cba9eb6f3e /src
parentbc8f9f28a3aaba7c9708720cfac632700bc66c18 (diff)
Cleanup IdentifierHash
This class is only used in one place, so there's no point in it being a template. Change-Id: Ibbbed8d5be1d02015339c9b39cd1b167f36b8885 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/compiler/qv4compileddata.cpp4
-rw-r--r--src/qml/compiler/qv4compileddata_p.h4
-rw-r--r--src/qml/jsruntime/qv4identifier.cpp16
-rw-r--r--src/qml/jsruntime/qv4identifier_p.h102
-rw-r--r--src/qml/jsruntime/qv4qmlcontext.cpp4
-rw-r--r--src/qml/qml/qqmlcontext.cpp12
-rw-r--r--src/qml/qml/qqmlcontext_p.h6
7 files changed, 54 insertions, 94 deletions
diff --git a/src/qml/compiler/qv4compileddata.cpp b/src/qml/compiler/qv4compileddata.cpp
index d889e634c0..e98cb32250 100644
--- a/src/qml/compiler/qv4compileddata.cpp
+++ b/src/qml/compiler/qv4compileddata.cpp
@@ -251,11 +251,11 @@ void CompilationUnit::markObjects(QV4::MarkStack *markStack)
}
}
-IdentifierHash<int> CompilationUnit::namedObjectsPerComponent(int componentObjectIndex)
+IdentifierHash CompilationUnit::namedObjectsPerComponent(int componentObjectIndex)
{
auto it = namedObjectsPerComponentCache.find(componentObjectIndex);
if (it == namedObjectsPerComponentCache.end()) {
- IdentifierHash<int> namedObjectCache(engine);
+ IdentifierHash namedObjectCache(engine);
const CompiledData::Object *component = data->objectAt(componentObjectIndex);
const quint32_le *namedObjectIndexPtr = component->namedObjectsInComponentTable();
for (quint32 i = 0; i < component->nNamedObjectsInComponent; ++i, ++namedObjectIndexPtr) {
diff --git a/src/qml/compiler/qv4compileddata_p.h b/src/qml/compiler/qv4compileddata_p.h
index 55c5f1f29f..bf3901a501 100644
--- a/src/qml/compiler/qv4compileddata_p.h
+++ b/src/qml/compiler/qv4compileddata_p.h
@@ -941,8 +941,8 @@ public:
// mapping from component object index (CompiledData::Unit object index that points to component) to identifier hash of named objects
// this is initialized on-demand by QQmlContextData
- QHash<int, IdentifierHash<int>> namedObjectsPerComponentCache;
- IdentifierHash<int> namedObjectsPerComponent(int componentObjectIndex);
+ QHash<int, IdentifierHash> namedObjectsPerComponentCache;
+ IdentifierHash namedObjectsPerComponent(int componentObjectIndex);
void finalizeCompositeType(QQmlEnginePrivate *qmlEngine);
diff --git a/src/qml/jsruntime/qv4identifier.cpp b/src/qml/jsruntime/qv4identifier.cpp
index e35f72b820..116d4ec201 100644
--- a/src/qml/jsruntime/qv4identifier.cpp
+++ b/src/qml/jsruntime/qv4identifier.cpp
@@ -75,13 +75,13 @@ IdentifierHashData::IdentifierHashData(IdentifierHashData *other)
memcpy(entries, other->entries, alloc*sizeof(IdentifierHashEntry));
}
-IdentifierHashBase::IdentifierHashBase(ExecutionEngine *engine)
+IdentifierHash::IdentifierHash(ExecutionEngine *engine)
{
d = new IdentifierHashData(3);
d->identifierTable = engine->identifierTable;
}
-void IdentifierHashBase::detach()
+void IdentifierHash::detach()
{
if (!d || d->refCount == 1)
return;
@@ -92,7 +92,7 @@ void IdentifierHashBase::detach()
}
-IdentifierHashEntry *IdentifierHashBase::addEntry(const Identifier *identifier)
+IdentifierHashEntry *IdentifierHash::addEntry(const Identifier *identifier)
{
// fill up to max 50%
bool grow = (d->alloc <= d->size*2);
@@ -129,7 +129,7 @@ IdentifierHashEntry *IdentifierHashBase::addEntry(const Identifier *identifier)
return d->entries + idx;
}
-const IdentifierHashEntry *IdentifierHashBase::lookup(const Identifier *identifier) const
+const IdentifierHashEntry *IdentifierHash::lookup(const Identifier *identifier) const
{
if (!d)
return 0;
@@ -146,7 +146,7 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(const Identifier *identifi
}
}
-const IdentifierHashEntry *IdentifierHashBase::lookup(const QString &str) const
+const IdentifierHashEntry *IdentifierHash::lookup(const QString &str) const
{
if (!d)
return 0;
@@ -164,7 +164,7 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(const QString &str) const
}
}
-const IdentifierHashEntry *IdentifierHashBase::lookup(String *str) const
+const IdentifierHashEntry *IdentifierHash::lookup(String *str) const
{
if (!d)
return 0;
@@ -173,13 +173,13 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(String *str) const
return lookup(str->toQString());
}
-const Identifier *IdentifierHashBase::toIdentifier(const QString &str) const
+const Identifier *IdentifierHash::toIdentifier(const QString &str) const
{
Q_ASSERT(d);
return d->identifierTable->identifier(str);
}
-const Identifier *IdentifierHashBase::toIdentifier(Heap::String *str) const
+const Identifier *IdentifierHash::toIdentifier(Heap::String *str) const
{
Q_ASSERT(d);
return d->identifierTable->identifier(str);
diff --git a/src/qml/jsruntime/qv4identifier_p.h b/src/qml/jsruntime/qv4identifier_p.h
index 2695bbc875..f0ff987608 100644
--- a/src/qml/jsruntime/qv4identifier_p.h
+++ b/src/qml/jsruntime/qv4identifier_p.h
@@ -73,13 +73,7 @@ struct Identifier
struct IdentifierHashEntry {
const Identifier *identifier;
- union {
- int value;
- void *pointer;
- };
- static int get(const IdentifierHashEntry *This, int *) { return This ? This->value : -1; }
- static bool get(const IdentifierHashEntry *This, bool *) { return This != 0; }
- static void *get(const IdentifierHashEntry *This, void **) { return This ? This->pointer : 0; }
+ int value;
};
struct IdentifierHashData
@@ -98,26 +92,30 @@ struct IdentifierHashData
IdentifierHashEntry *entries;
};
-struct IdentifierHashBase
+struct IdentifierHash
{
IdentifierHashData *d;
- IdentifierHashBase() : d(0) {}
- IdentifierHashBase(ExecutionEngine *engine);
- inline IdentifierHashBase(const IdentifierHashBase &other);
- inline ~IdentifierHashBase();
- inline IdentifierHashBase &operator=(const IdentifierHashBase &other);
+ IdentifierHash() : d(0) {}
+ IdentifierHash(ExecutionEngine *engine);
+ inline IdentifierHash(const IdentifierHash &other);
+ inline ~IdentifierHash();
+ inline IdentifierHash &operator=(const IdentifierHash &other);
bool isEmpty() const { return !d; }
inline int count() const;
- bool contains(const Identifier *i) const;
- bool contains(const QString &str) const;
- bool contains(String *str) const;
void detach();
+ void add(const QString &str, int value);
+ void add(Heap::String *str, int value);
+
+ inline int value(const QString &str) const;
+ inline int value(String *str) const;
+ QString findId(int value) const;
+
protected:
IdentifierHashEntry *addEntry(const Identifier *i);
const IdentifierHashEntry *lookup(const Identifier *identifier) const;
@@ -128,43 +126,20 @@ protected:
};
-template<typename T>
-struct IdentifierHash : public IdentifierHashBase
-{
- IdentifierHash()
- : IdentifierHashBase() {}
- IdentifierHash(ExecutionEngine *engine)
- : IdentifierHashBase(engine) {}
- inline IdentifierHash(const IdentifierHash<T> &other)
- : IdentifierHashBase(other) {}
- inline ~IdentifierHash() {}
- inline IdentifierHash &operator=(const IdentifierHash<T> &other) {
- IdentifierHashBase::operator =(other);
- return *this;
- }
-
- void add(const QString &str, const T &value);
- void add(Heap::String *str, const T &value);
-
- inline T value(const QString &str) const;
- inline T value(String *str) const;
- QString findId(T value) const;
-};
-
-inline IdentifierHashBase::IdentifierHashBase(const IdentifierHashBase &other)
+inline IdentifierHash::IdentifierHash(const IdentifierHash &other)
{
d = other.d;
if (d)
d->refCount.ref();
}
-inline IdentifierHashBase::~IdentifierHashBase()
+inline IdentifierHash::~IdentifierHash()
{
if (d && !d->refCount.deref())
delete d;
}
-IdentifierHashBase &IdentifierHashBase::operator=(const IdentifierHashBase &other)
+IdentifierHash &IdentifierHash::operator=(const IdentifierHash &other)
{
if (other.d)
other.d->refCount.ref();
@@ -174,60 +149,45 @@ IdentifierHashBase &IdentifierHashBase::operator=(const IdentifierHashBase &othe
return *this;
}
-inline int IdentifierHashBase::count() const
+inline int IdentifierHash::count() const
{
return d ? d->size : 0;
}
-inline bool IdentifierHashBase::contains(const Identifier *i) const
-{
- return lookup(i) != 0;
-}
-
-inline bool IdentifierHashBase::contains(const QString &str) const
-{
- return lookup(str) != 0;
-}
-
-inline bool IdentifierHashBase::contains(String *str) const
-{
- return lookup(str) != 0;
-}
-
-template<typename T>
-void IdentifierHash<T>::add(const QString &str, const T &value)
+inline
+void IdentifierHash::add(const QString &str, int value)
{
IdentifierHashEntry *e = addEntry(toIdentifier(str));
e->value = value;
}
-template<typename T>
-void IdentifierHash<T>::add(Heap::String *str, const T &value)
+inline
+void IdentifierHash::add(Heap::String *str, int value)
{
IdentifierHashEntry *e = addEntry(toIdentifier(str));
e->value = value;
}
-template<typename T>
-inline T IdentifierHash<T>::value(const QString &str) const
+inline int IdentifierHash::value(const QString &str) const
{
- return IdentifierHashEntry::get(lookup(str), (T*)0);
+ const IdentifierHashEntry *e = lookup(str);
+ return e ? e->value : -1;
}
-template<typename T>
-inline T IdentifierHash<T>::value(String *str) const
+inline int IdentifierHash::value(String *str) const
{
- return IdentifierHashEntry::get(lookup(str), (T*)0);
+ const IdentifierHashEntry *e = lookup(str);
+ return e ? e->value : -1;
}
-template<typename T>
-QString IdentifierHash<T>::findId(T value) const
+inline
+QString IdentifierHash::findId(int value) const
{
IdentifierHashEntry *e = d->entries;
IdentifierHashEntry *end = e + d->alloc;
while (e < end) {
- if (e->identifier && IdentifierHashEntry::get(e, (T*)0) == value)
+ if (e->identifier && e->value == value)
return e->identifier->string;
++e;
}
diff --git a/src/qml/jsruntime/qv4qmlcontext.cpp b/src/qml/jsruntime/qv4qmlcontext.cpp
index 5a165b2309..21af4270fd 100644
--- a/src/qml/jsruntime/qv4qmlcontext.cpp
+++ b/src/qml/jsruntime/qv4qmlcontext.cpp
@@ -154,7 +154,7 @@ ReturnedValue QQmlContextWrapper::get(const Managed *m, String *name, bool *hasP
while (context) {
// Search context properties
- const QV4::IdentifierHash<int> &properties = context->propertyNames();
+ const QV4::IdentifierHash &properties = context->propertyNames();
if (properties.count()) {
int propertyIdx = properties.value(name);
@@ -261,7 +261,7 @@ bool QQmlContextWrapper::put(Managed *m, String *name, const Value &value)
QObject *scopeObject = wrapper->getScopeObject();
while (context) {
- const QV4::IdentifierHash<int> &properties = context->propertyNames();
+ const QV4::IdentifierHash &properties = context->propertyNames();
// Search context properties
if (properties.count() && properties.value(name) != -1)
return false;
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp
index fbf73a944c..a32ed6e998 100644
--- a/src/qml/qml/qqmlcontext.cpp
+++ b/src/qml/qml/qqmlcontext.cpp
@@ -306,7 +306,7 @@ void QQmlContext::setContextProperty(const QString &name, const QVariant &value)
return;
}
- QV4::IdentifierHash<int> &properties = data->detachedPropertyNames();
+ QV4::IdentifierHash &properties = data->detachedPropertyNames();
int idx = properties.value(name);
if (idx == -1) {
properties.add(name, data->idValueCount + d->propertyValues.count());
@@ -341,7 +341,7 @@ QVariant QQmlContext::contextProperty(const QString &name) const
QQmlContextData *data = d->data;
- const QV4::IdentifierHash<int> &properties = data->propertyNames();
+ const QV4::IdentifierHash &properties = data->propertyNames();
if (properties.count())
idx = properties.value(name);
@@ -746,7 +746,7 @@ void QQmlContextData::setIdProperty(int idx, QObject *obj)
QString QQmlContextData::findObjectId(const QObject *obj) const
{
- const QV4::IdentifierHash<int> &properties = propertyNames();
+ const QV4::IdentifierHash &properties = propertyNames();
if (propertyNameCache.isEmpty())
return QString();
@@ -788,18 +788,18 @@ void QQmlContextData::initFromTypeCompilationUnit(const QQmlRefPointer<QV4::Comp
idValues = new ContextGuard[idValueCount];
}
-const QV4::IdentifierHash<int> &QQmlContextData::propertyNames() const
+const QV4::IdentifierHash &QQmlContextData::propertyNames() const
{
if (propertyNameCache.isEmpty()) {
if (typeCompilationUnit)
propertyNameCache = typeCompilationUnit->namedObjectsPerComponent(componentObjectIndex);
else
- propertyNameCache = QV4::IdentifierHash<int>(QV8Engine::getV4(engine));
+ propertyNameCache = QV4::IdentifierHash(QV8Engine::getV4(engine));
}
return propertyNameCache;
}
-QV4::IdentifierHash<int> &QQmlContextData::detachedPropertyNames()
+QV4::IdentifierHash &QQmlContextData::detachedPropertyNames()
{
propertyNames();
propertyNameCache.detach();
diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h
index d01820a430..8939c810fe 100644
--- a/src/qml/qml/qqmlcontext_p.h
+++ b/src/qml/qml/qqmlcontext_p.h
@@ -158,9 +158,9 @@ public:
void initFromTypeCompilationUnit(const QQmlRefPointer<QV4::CompiledData::CompilationUnit> &unit, int subComponentIndex);
// flag indicates whether the context owns the cache (after mutation) or not.
- mutable QV4::IdentifierHash<int> propertyNameCache;
- const QV4::IdentifierHash<int> &propertyNames() const;
- QV4::IdentifierHash<int> &detachedPropertyNames();
+ mutable QV4::IdentifierHash propertyNameCache;
+ const QV4::IdentifierHash &propertyNames() const;
+ QV4::IdentifierHash &detachedPropertyNames();
// Context object
QObject *contextObject;