diff options
author | Simon Hausmann <[email protected]> | 2013-08-09 16:45:02 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-08-12 13:29:27 +0200 |
commit | 7c2adbbb6cccefd202164049dc9144b4d13aec0a (patch) | |
tree | 7410500f53aac1b8fe2a46729db48732744ebf4b /src/qml/jsruntime/qv4function_p.h | |
parent | 42dc821dd68cc63aa8300f2678639dbaacda1057 (diff) |
Add reference counting to the VM functions
This reduces memory pressure, keep engine->functions small and thus makes back
trace lookup faster. It became visible for example in the QtQuickControls
auto-tests that use plenty of loaders and we ended up with 30k+ functions.
Change-Id: Iaa5981f44e1e49ad9417a50c1e6a74946090dd28
Reviewed-by: Lars Knoll <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4function_p.h')
-rw-r--r-- | src/qml/jsruntime/qv4function_p.h | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4function_p.h b/src/qml/jsruntime/qv4function_p.h index 3ff31ed2e3..612bbb122e 100644 --- a/src/qml/jsruntime/qv4function_p.h +++ b/src/qml/jsruntime/qv4function_p.h @@ -87,6 +87,7 @@ struct LineNumberMapping }; struct Function { + int refCount; String *name; Value (*code)(ExecutionContext *, const uchar *); @@ -111,8 +112,11 @@ struct Function { QString sourceFile; QVector<LineNumberMapping> lineNumberMappings; - Function(String *name) - : name(name) + ExecutionEngine *engine; + + Function(ExecutionEngine *engine, String *name) + : refCount(0) + , name(name) , code(0) , codeData(0) , codeSize(0) @@ -122,9 +126,19 @@ struct Function { , usesArgumentsObject(false) , isStrict(false) , isNamedExpression(false) + , engine(engine) {} ~Function(); + void ref() { ++refCount; } + void deref() { if (!--refCount) delete this; } + + void addNestedFunction(Function *f) + { + f->ref(); + nestedFunctions.append(f); + } + inline bool needsActivation() const { return hasNestedFunctions || hasDirectEval || usesArgumentsObject; } void mark(); |