QmlJS: Refactor LookupContext creation for speed.

* If possible, create LookupContexts through SemanticInfo; it caches the
  linked Context and will be faster.
* Contexts now own their Engine.

Reviewed-by: Lasse Holmstedt
This commit is contained in:
Christian Kamm
2010-08-26 10:50:00 +02:00
parent af46c3d947
commit 87e04df257
15 changed files with 141 additions and 96 deletions

View File

@@ -40,20 +40,30 @@ class QmlJS::LookupContextData
{
public:
LookupContextData(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
: context(&interp),
: doc(doc),
snapshot(snapshot)
{
// since we keep the document and snapshot around, we don't need to keep the Link instance
Link link(&context, doc, snapshot, ModelManagerInterface::instance()->importPaths());
ScopeBuilder scopeBuilder(doc, &context);
scopeBuilder.push(path);
}
LookupContextData(Document::Ptr doc, const Snapshot &snapshot,
const Interpreter::Context &linkedContextWithoutScope,
const QList<AST::Node *> &path)
: context(linkedContextWithoutScope),
doc(doc),
snapshot(snapshot),
link(&context, doc, snapshot, ModelManagerInterface::instance()->importPaths())
snapshot(snapshot)
{
ScopeBuilder scopeBuilder(doc, &context);
scopeBuilder.push(path);
}
Interpreter::Engine interp;
Interpreter::Context context;
Document::Ptr doc;
Snapshot snapshot;
Link link;
};
LookupContext::LookupContext(Document::Ptr doc, const Snapshot &snapshot, const QList<AST::Node *> &path)
@@ -61,6 +71,13 @@ LookupContext::LookupContext(Document::Ptr doc, const Snapshot &snapshot, const
{
}
LookupContext::LookupContext(const Document::Ptr doc, const Snapshot &snapshot,
const Interpreter::Context &linkedContextWithoutScope,
const QList<AST::Node *> &path)
: d(new LookupContextData(doc, snapshot, linkedContextWithoutScope, path))
{
}
LookupContext::~LookupContext()
{
}
@@ -71,17 +88,37 @@ LookupContext::Ptr LookupContext::create(Document::Ptr doc, const Snapshot &snap
return ptr;
}
LookupContext::Ptr LookupContext::create(const Document::Ptr doc, const Snapshot &snapshot,
const Interpreter::Context &linkedContextWithoutScope,
const QList<AST::Node *> &path)
{
Ptr ptr(new LookupContext(doc, snapshot, linkedContextWithoutScope, path));
return ptr;
}
const Interpreter::Value *LookupContext::evaluate(AST::Node *node) const
{
Evaluate check(&d->context);
return check(node);
}
Interpreter::Engine *LookupContext::engine() const
Document::Ptr LookupContext::document() const
{
return &d->interp;
return d->doc;
}
Snapshot LookupContext::snapshot() const
{
return d->snapshot;
}
// the engine is only guaranteed to live as long as the LookupContext
Interpreter::Engine *LookupContext::engine() const
{
return d->context.engine();
}
// the context is only guaranteed to live as long as the LookupContext
const Interpreter::Context *LookupContext::context() const
{
return &d->context;