Commit 0c0ffab1 authored by Fawzi Mohamed's avatar Fawzi Mohamed
Browse files

avoid allocating QmlEnumValues each time

Change-Id: I61f39f5bafcb2c84e91f5bca4b52010a08ed9f37
Reviewed-on: http://codereview.qt.nokia.com/1592

Reviewed-by: default avatarQt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: default avatarChristian Kamm <christian.d.kamm@nokia.com>
parent 4becd473
......@@ -161,9 +161,15 @@ QmlObjectValue::QmlObjectValue(FakeMetaObject::ConstPtr metaObject, const QStrin
_attachedType(0),
_metaObject(metaObject),
_packageName(packageName),
_componentVersion(version)
_componentVersion(version),
_enums()
{
setClassName(className);
int nEnums = metaObject->enumeratorCount();
for (int i = 0; i < nEnums; ++i) {
FakeMetaEnum fEnum = metaObject->enumerator(i);
_enums[fEnum.name()] = new QmlEnumValue(fEnum, valueOwner);
}
}
QmlObjectValue::~QmlObjectValue()
......@@ -307,9 +313,7 @@ const Value *QmlObjectValue::propertyValue(const FakeMetaProperty &prop) const
typeName = components.last();
}
if (base) {
const FakeMetaEnum &metaEnum = base->getEnum(typeName);
if (metaEnum.isValid())
value = new QmlEnumValue(metaEnum, valueOwner());
value = base->getEnumValue(typeName);
}
return value;
......@@ -378,6 +382,11 @@ FakeMetaEnum QmlObjectValue::getEnum(const QString &typeName) const
return _metaObject->enumerator(index);
}
const QmlEnumValue *QmlObjectValue::getEnumValue(const QString &typeName) const
{
return _enums.value(typeName, 0);
}
bool QmlObjectValue::isWritable(const QString &propertyName) const
{
for (const QmlObjectValue *it = this; it; it = it->prototype()) {
......
......@@ -421,6 +421,20 @@ private:
Error m_error;
};
class QMLJS_EXPORT QmlEnumValue: public NumberValue
{
public:
QmlEnumValue(const LanguageUtils::FakeMetaEnum &metaEnum, ValueOwner *valueOwner);
virtual ~QmlEnumValue();
QString name() const;
QStringList keys() const;
private:
LanguageUtils::FakeMetaEnum *_metaEnum;
};
// A ObjectValue based on a FakeMetaObject.
// May only have other QmlObjectValues as ancestors.
class QMLJS_EXPORT QmlObjectValue: public ObjectValue
......@@ -455,6 +469,7 @@ public:
bool hasChildInPackage() const;
LanguageUtils::FakeMetaEnum getEnum(const QString &typeName) const;
const QmlEnumValue *getEnumValue(const QString &typeName) const;
protected:
const Value *findOrCreateSignature(int index, const LanguageUtils::FakeMetaMethod &method,
QString *methodName) const;
......@@ -466,19 +481,7 @@ private:
const QString _packageName;
const LanguageUtils::ComponentVersion _componentVersion;
mutable QHash<int, const Value *> _metaSignature;
};
class QMLJS_EXPORT QmlEnumValue: public NumberValue
{
public:
QmlEnumValue(const LanguageUtils::FakeMetaEnum &metaEnum, ValueOwner *valueOwner);
virtual ~QmlEnumValue();
QString name() const;
QStringList keys() const;
private:
LanguageUtils::FakeMetaEnum *_metaEnum;
QHash<QString, const QmlEnumValue * > _enums;
};
class QMLJS_EXPORT Activation
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment