aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@live.com>2014-02-27 15:59:39 -0600
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-28 19:01:21 +0100
commita3688bf41fd42befe7ab83a633dbbd71eda56cd9 (patch)
tree042d3b4a4a78f6787a6c641e09ff957b62b40aa5 /src/qml/jsruntime
parent0b2d05093c6fc030d40be8c873ad1e0af9bba8cc (diff)
Improve memory usage in QML/V4 engine.
* Don't create prototype Object for bindings and signal handlers. It is inaccessible and not required. This saves one Object-sized allocation per binding. * Shrink the size of QQmlContextWrapper by removing the v8 member variable. * Shrink the size of QObjectWrapper by moving the destroy identifier to the engine. Change-Id: I76e84e4c0581e97a19d2e959f814ac84d9c431fa Task-number: QTBUG-37134 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp2
-rw-r--r--src/qml/jsruntime/qv4engine_p.h1
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp8
-rw-r--r--src/qml/jsruntime/qv4functionobject_p.h4
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper.cpp8
-rw-r--r--src/qml/jsruntime/qv4qobjectwrapper_p.h1
-rw-r--r--src/qml/jsruntime/qv4runtime.cpp2
7 files changed, 13 insertions, 13 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 885186e86b..56ca31c85d 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -246,6 +246,7 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
id_index = newIdentifier(QStringLiteral("index"));
id_input = newIdentifier(QStringLiteral("input"));
id_toString = newIdentifier(QStringLiteral("toString"));
+ id_destroy = newIdentifier(QStringLiteral("destroy"));
id_valueOf = newIdentifier(QStringLiteral("valueOf"));
ObjectPrototype *objectPrototype = new (memoryManager) ObjectPrototype(InternalClass::create(this, ObjectPrototype::staticVTable(), 0));
@@ -863,6 +864,7 @@ void ExecutionEngine::markObjects()
id_index->mark(this);
id_input->mark(this);
id_toString->mark(this);
+ id_destroy->mark(this);
id_valueOf->mark(this);
objectCtor.mark(this);
diff --git a/src/qml/jsruntime/qv4engine_p.h b/src/qml/jsruntime/qv4engine_p.h
index d8ac750e75..4bf95c4868 100644
--- a/src/qml/jsruntime/qv4engine_p.h
+++ b/src/qml/jsruntime/qv4engine_p.h
@@ -263,6 +263,7 @@ public:
StringValue id_index;
StringValue id_input;
StringValue id_toString;
+ StringValue id_destroy;
StringValue id_valueOf;
QSet<CompiledData::CompilationUnit*> compilationUnits;
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 07ec94a58d..66e956e43c 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -183,14 +183,14 @@ void FunctionObject::markObjects(Managed *that, ExecutionEngine *e)
Object::markObjects(that, e);
}
-FunctionObject *FunctionObject::creatScriptFunction(ExecutionContext *scope, Function *function)
+FunctionObject *FunctionObject::creatScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
{
if (function->needsActivation() ||
function->compiledFunction->flags & CompiledData::Function::HasCatchOrWith ||
function->compiledFunction->nFormals > QV4::Global::ReservedArgumentCount ||
function->isNamedExpression())
return new (scope->engine->memoryManager) ScriptFunction(scope, function);
- return new (scope->engine->memoryManager) SimpleScriptFunction(scope, function);
+ return new (scope->engine->memoryManager) SimpleScriptFunction(scope, function, createProto);
}
ReturnedValue FunctionObject::protoProperty()
@@ -482,8 +482,8 @@ ReturnedValue ScriptFunction::call(Managed *that, CallData *callData)
DEFINE_OBJECT_VTABLE(SimpleScriptFunction);
-SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function)
- : FunctionObject(scope, function->name, true)
+SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
+ : FunctionObject(scope, function->name, createProto)
{
setVTable(staticVTable());
diff --git a/src/qml/jsruntime/qv4functionobject_p.h b/src/qml/jsruntime/qv4functionobject_p.h
index af4ec024d5..1f5bced8f8 100644
--- a/src/qml/jsruntime/qv4functionobject_p.h
+++ b/src/qml/jsruntime/qv4functionobject_p.h
@@ -137,7 +137,7 @@ struct Q_QML_EXPORT FunctionObject: Object {
return v.asFunctionObject();
}
- static FunctionObject *creatScriptFunction(ExecutionContext *scope, Function *function);
+ static FunctionObject *creatScriptFunction(ExecutionContext *scope, Function *function, bool createProto = true);
ReturnedValue protoProperty();
InternalClass *internalClassForConstructor();
@@ -221,7 +221,7 @@ struct ScriptFunction: FunctionObject {
struct SimpleScriptFunction: FunctionObject {
V4_OBJECT
- SimpleScriptFunction(ExecutionContext *scope, Function *function);
+ SimpleScriptFunction(ExecutionContext *scope, Function *function, bool createProto);
static ReturnedValue construct(Managed *, CallData *callData);
static ReturnedValue call(Managed *that, CallData *callData);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper.cpp b/src/qml/jsruntime/qv4qobjectwrapper.cpp
index 7f4ac22377..14533946e1 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper.cpp
+++ b/src/qml/jsruntime/qv4qobjectwrapper.cpp
@@ -245,8 +245,6 @@ QObjectWrapper::QObjectWrapper(ExecutionEngine *engine, QObject *object)
Scope scope(engine);
ScopedObject protectThis(scope, this);
-
- m_destroy = engine->newIdentifier(QStringLiteral("destroy"));
}
void QObjectWrapper::initializeBindings(ExecutionEngine *engine)
@@ -282,8 +280,8 @@ ReturnedValue QObjectWrapper::getQmlProperty(ExecutionContext *ctx, QQmlContextD
QV4::Scope scope(ctx);
QV4::ScopedString name(scope, n);
- if (name->equals(m_destroy) || name->equals(scope.engine->id_toString)) {
- int index = name->equals(m_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
+ if (name->equals(scope.engine->id_destroy) || name->equals(scope.engine->id_toString)) {
+ int index = name->equals(scope.engine->id_destroy) ? QV4::QObjectMethod::DestroyMethod : QV4::QObjectMethod::ToStringMethod;
QV4::ScopedValue method(scope, QV4::QObjectMethod::create(ctx->engine->rootContext, m_object, index));
if (hasProperty)
*hasProperty = true;
@@ -695,7 +693,7 @@ PropertyAttributes QObjectWrapper::query(const Managed *m, StringRef name)
QQmlContextData *qmlContext = QV4::QmlContextWrapper::callingContext(engine);
QQmlPropertyData local;
if (that->findProperty(engine, qmlContext, name, IgnoreRevision, &local)
- || name->equals(const_cast<StringValue &>(that->m_destroy)) || name->equals(engine->id_toString))
+ || name->equals(engine->id_destroy) || name->equals(engine->id_toString))
return QV4::Attr_Data;
else
return QV4::Object::query(m, name);
diff --git a/src/qml/jsruntime/qv4qobjectwrapper_p.h b/src/qml/jsruntime/qv4qobjectwrapper_p.h
index ca38c5b0dc..b11f0af93f 100644
--- a/src/qml/jsruntime/qv4qobjectwrapper_p.h
+++ b/src/qml/jsruntime/qv4qobjectwrapper_p.h
@@ -111,7 +111,6 @@ private:
QQmlPropertyData *findProperty(ExecutionEngine *engine, QQmlContextData *qmlContext, String *name, RevisionMode revisionMode, QQmlPropertyData *local) const;
QPointer<QObject> m_object;
- StringValue m_destroy;
static ReturnedValue get(Managed *m, const StringRef name, bool *hasProperty);
static void put(Managed *m, const StringRef name, const ValueRef value);
diff --git a/src/qml/jsruntime/qv4runtime.cpp b/src/qml/jsruntime/qv4runtime.cpp
index a3ba4b0d75..2b63632780 100644
--- a/src/qml/jsruntime/qv4runtime.cpp
+++ b/src/qml/jsruntime/qv4runtime.cpp
@@ -1297,7 +1297,7 @@ ReturnedValue __qmljs_get_imported_scripts(NoThrowContext *ctx)
QV4::ReturnedValue __qmljs_get_qml_singleton(QV4::NoThrowContext *ctx, const QV4::StringRef name)
{
- return ctx->engine->qmlContextObject()->getPointer()->as<QmlContextWrapper>()->qmlSingletonWrapper(name);
+ return ctx->engine->qmlContextObject()->getPointer()->as<QmlContextWrapper>()->qmlSingletonWrapper(ctx->engine->v8Engine, name);
}
void __qmljs_builtin_convert_this_to_object(ExecutionContext *ctx)