aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4script.cpp
diff options
context:
space:
mode:
authorSimon Hausmann <simon.hausmann@digia.com>2013-10-16 14:03:48 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-10-16 16:03:57 +0200
commit12c3579136b6925e75cca4f3a9b8bae2e4665db7 (patch)
tree17f82a28141856af0954ffe4eff20ebc679a3265 /src/qml/jsruntime/qv4script.cpp
parentc1c526aafb2fc70ac6155eb775b3784f1e2e6504 (diff)
Speed up exception propagation
Avoid catch (...) with re-throw as it turns that this is very slow because it throws a new exception and the unwinder starts from scratch. Instead use stack allocated objects and cleaning destructors to restore state before continuing with the propagation of exceptions. Change-Id: I6d95026bcd60b58cb6258a9dae28623a46739532 Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4script.cpp')
-rw-r--r--src/qml/jsruntime/qv4script.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/qml/jsruntime/qv4script.cpp b/src/qml/jsruntime/qv4script.cpp
index 885ea8ea76..d30132140b 100644
--- a/src/qml/jsruntime/qv4script.cpp
+++ b/src/qml/jsruntime/qv4script.cpp
@@ -227,6 +227,27 @@ void Script::parse()
ReturnedValue Script::run()
{
+ struct ContextStateSaver {
+ ExecutionContext *savedContext;
+ bool strictMode;
+ Lookup *lookups;
+ CompiledData::CompilationUnit *compilationUnit;
+
+ ContextStateSaver(ExecutionContext *context)
+ : savedContext(context)
+ , strictMode(context->strictMode)
+ , lookups(context->lookups)
+ , compilationUnit(context->compilationUnit)
+ {}
+
+ ~ContextStateSaver()
+ {
+ savedContext->strictMode = strictMode;
+ savedContext->lookups = lookups;
+ savedContext->compilationUnit = compilationUnit;
+ }
+ };
+
if (!parsed)
parse();
if (!vmFunction)
@@ -238,29 +259,13 @@ ReturnedValue Script::run()
if (qml.isUndefined()) {
TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, vmFunction);
- bool strict = scope->strictMode;
- Lookup *oldLookups = scope->lookups;
- CompiledData::CompilationUnit * const oldCompilationUnit = scope->compilationUnit;
-
+ ExecutionContextSaver ctxSaver(scope);
+ ContextStateSaver stateSaver(scope);
scope->strictMode = vmFunction->isStrict();
scope->lookups = vmFunction->compilationUnit->runtimeLookups;
scope->compilationUnit = vmFunction->compilationUnit;
- QV4::ScopedValue result(valueScope);
- try {
- result = vmFunction->code(scope, vmFunction->codeData);
- } catch (...) {
- scope->strictMode = strict;
- scope->lookups = oldLookups;
- scope->compilationUnit = oldCompilationUnit;
- scope->rethrowException();
- }
-
- scope->lookups = oldLookups;
- scope->compilationUnit = oldCompilationUnit;
-
- return result.asReturnedValue();
-
+ return vmFunction->code(scope, vmFunction->codeData);
} else {
ScopedObject qmlObj(valueScope, qml.value());
FunctionObject *f = new (engine->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj);