diff options
author | Lars Knoll <[email protected]> | 2013-08-21 14:52:15 +0200 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-09-02 17:27:36 +0200 |
commit | 29f946cdad013d759aad05cbd22f40d0c152d6f3 (patch) | |
tree | 122bcf437d9c9f55bd5dabab7f0a278e440f339c /src/qml/jsruntime/qv4context.cpp | |
parent | ac1d0075a8a379de1aa31a588c7b86ce0813e48c (diff) |
Add a SimpleScriptFunction class
Choose whether we use a stack based context for a function, when
the actual closure is generated, not at call time. This speeds up
function calling for leaf functions.
Change-Id: Ibcbf3acb5610a7f59b6474e982122df03c1c5298
Reviewed-by: Simon Hausmann <[email protected]>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4context.cpp | 65 |
1 files changed, 50 insertions, 15 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp index f30a1fc896..21a11bbdec 100644 --- a/src/qml/jsruntime/qv4context.cpp +++ b/src/qml/jsruntime/qv4context.cpp @@ -53,16 +53,10 @@ using namespace QV4; CallContext *ExecutionContext::newCallContext(void *stackSpace, FunctionObject *function, const Value &thisObject, Value *args, int argc) { - CallContext *c; - uint memory = requiredMemoryForExecutionContect(function, argc); - if (function->needsActivation || memory > stackContextSize) { - c = static_cast<CallContext *>(engine->memoryManager->allocContext(memory)); - } else { - c = (CallContext *)stackSpace; + CallContext *c = (CallContext *)stackSpace; #ifndef QT_NO_DEBUG - c->next = (CallContext *)0x1; + c->next = (CallContext *)0x1; #endif - } engine->current = c; @@ -91,19 +85,60 @@ CallContext *ExecutionContext::newCallContext(void *stackSpace, FunctionObject * } c->locals = (Value *)(c + 1); + if (function->varCount) std::fill(c->locals, c->locals + function->varCount, Value::undefinedValue()); - if (c->needsOwnArguments()) { - c->argumentCount = qMax((uint)argc, function->formalParameterCount); - c->arguments = c->locals + function->varCount; - if (argc) - ::memcpy(c->arguments, args, argc * sizeof(Value)); - if (argc < function->formalParameterCount) - std::fill(c->arguments + argc, c->arguments + function->formalParameterCount, Value::undefinedValue()); + if (argc < function->formalParameterCount) { + std::fill(c->arguments + argc, c->arguments + function->formalParameterCount, Value::undefinedValue()); + c->argumentCount = function->formalParameterCount; + } + + return c; +} + +CallContext *ExecutionContext::newCallContext(FunctionObject *function, const Value &thisObject, Value *args, int argc) +{ + CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocContext(requiredMemoryForExecutionContect(function, argc))); + + engine->current = c; + + c->initBaseContext(Type_CallContext, engine, this); + + c->function = function; + c->arguments = args; + c->realArgumentCount = argc; + c->argumentCount = argc; + c->thisObject = thisObject; + + c->strictMode = function->strictMode; + c->marked = false; + c->outer = function->scope; +#ifndef QT_NO_DEBUG + assert(c->outer->next != (ExecutionContext *)0x1); +#endif + + c->activation = 0; + if (function->function) { + c->compilationUnit = function->function->compilationUnit; + c->compiledFunction = function->function->compiledFunction; + c->lookups = c->compilationUnit->runtimeLookups; + c->runtimeStrings = c->compilationUnit->runtimeStrings; } + c->locals = (Value *)(c + 1); + + if (function->varCount) + std::fill(c->locals, c->locals + function->varCount, Value::undefinedValue()); + + c->argumentCount = qMax((uint)argc, function->formalParameterCount); + c->arguments = c->locals + function->varCount; + if (argc) + ::memcpy(c->arguments, args, argc * sizeof(Value)); + if (argc < function->formalParameterCount) + std::fill(c->arguments + argc, c->arguments + function->formalParameterCount, Value::undefinedValue()); + return c; } |