aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4context.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-11-15 16:36:13 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-12-04 09:45:33 +0100
commit0fa9cf218bdd3054585f23abfb2b707e26ce987a (patch)
tree346592c0d570d138278c659dbbbbda23ec1d148d /src/qml/jsruntime/qv4context.cpp
parent608a9600142878574a509964941413bb15c91201 (diff)
Use an internalClass to represent formals and locals in CallContexts
formals and locals in a CallContext where so far accessed through a linear search in ExecutionContext::getProperty. Fix this by introducing an internalClass for the Function used by the call context. Change-Id: I1141efa12b19d6de4a354bfd6e769c5ffcb8898b Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r--src/qml/jsruntime/qv4context.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index b0fb535361..90e6850161 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -172,7 +172,7 @@ String * const *ExecutionContext::formals() const
if (type < Type_SimpleCallContext)
return 0;
QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function;
- return f ? f->formalParameterList : 0;
+ return (f && f->function) ? f->function->internalClass->nameMap.constData() : 0;
}
unsigned int ExecutionContext::formalCount() const
@@ -188,7 +188,7 @@ String * const *ExecutionContext::variables() const
if (type < Type_SimpleCallContext)
return 0;
QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function;
- return f ? f->varList : 0;
+ return (f && f->function) ? f->function->internalClass->nameMap.constData() + f->function->nArguments : 0;
}
unsigned int ExecutionContext::variableCount() const
@@ -282,12 +282,10 @@ bool ExecutionContext::deleteProperty(const StringRef name)
CallContext *c = static_cast<CallContext *>(ctx);
FunctionObject *f = c->function;
if (f->needsActivation || hasWith) {
- for (unsigned int i = 0; i < f->varCount; ++i)
- if (f->varList[i]->isEqualTo(name))
- return false;
- for (int i = (int)f->formalParameterCount - 1; i >= 0; --i)
- if (f->formalParameterList[i]->isEqualTo(name))
- return false;
+ uint index = f->function->internalClass->find(name);
+ if (index < UINT_MAX)
+ // ### throw in strict mode?
+ return false;
}
if (c->activation && c->activation->__hasProperty__(name))
return c->activation->deleteProperty(name);
@@ -357,16 +355,18 @@ void ExecutionContext::setProperty(const StringRef name, const ValueRef value)
ScopedObject activation(scope, (Object *)0);
if (ctx->type >= Type_CallContext) {
CallContext *c = static_cast<CallContext *>(ctx);
- for (unsigned int i = 0; i < c->function->varCount; ++i)
- if (c->function->varList[i]->isEqualTo(name)) {
- c->locals[i] = *value;
- return;
- }
- for (int i = (int)c->function->formalParameterCount - 1; i >= 0; --i)
- if (c->function->formalParameterList[i]->isEqualTo(name)) {
- c->callData->args[i] = *value;
+ if (c->function->function) {
+ uint index = c->function->function->internalClass->find(name);
+ if (index < UINT_MAX) {
+ if (index < c->function->formalParameterCount) {
+ c->callData->args[c->function->formalParameterCount - index - 1] = *value;
+ } else {
+ index -= c->function->formalParameterCount;
+ c->locals[index] = *value;
+ }
return;
}
+ }
activation = c->activation;
} else if (ctx->type == Type_GlobalContext) {
activation = static_cast<GlobalContext *>(ctx)->global;
@@ -419,13 +419,13 @@ ReturnedValue ExecutionContext::getProperty(const StringRef name)
else if (ctx->type >= Type_CallContext) {
QV4::CallContext *c = static_cast<CallContext *>(ctx);
ScopedFunctionObject f(scope, c->function);
- if (f->needsActivation || hasWith || hasCatchScope) {
- for (unsigned int i = 0; i < f->varCount; ++i)
- if (f->varList[i]->isEqualTo(name))
- return c->locals[i].asReturnedValue();
- for (int i = (int)f->formalParameterCount - 1; i >= 0; --i)
- if (f->formalParameterList[i]->isEqualTo(name))
- return c->callData->args[i].asReturnedValue();
+ if (f->function && (f->needsActivation || hasWith || hasCatchScope)) {
+ uint index = f->function->internalClass->find(name);
+ if (index < UINT_MAX) {
+ if (index < c->function->formalParameterCount)
+ return c->callData->args[c->function->formalParameterCount - index - 1].asReturnedValue();
+ return c->locals[index - c->function->formalParameterCount].asReturnedValue();
+ }
}
if (c->activation) {
bool hasProperty = false;
@@ -485,13 +485,13 @@ ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectR
else if (ctx->type >= Type_CallContext) {
QV4::CallContext *c = static_cast<CallContext *>(ctx);
FunctionObject *f = c->function;
- if (f->needsActivation || hasWith || hasCatchScope) {
- for (unsigned int i = 0; i < f->varCount; ++i)
- if (f->varList[i]->isEqualTo(name))
- return c->locals[i].asReturnedValue();
- for (int i = (int)f->formalParameterCount - 1; i >= 0; --i)
- if (f->formalParameterList[i]->isEqualTo(name))
- return c->callData->args[i].asReturnedValue();
+ if (f->function && (f->needsActivation || hasWith || hasCatchScope)) {
+ uint index = f->function->internalClass->find(name);
+ if (index < UINT_MAX) {
+ if (index < c->function->formalParameterCount)
+ return c->callData->args[c->function->formalParameterCount - index - 1].asReturnedValue();
+ return c->locals[index - c->function->formalParameterCount].asReturnedValue();
+ }
}
if (c->activation) {
bool hasProperty = false;