Commit 20f35027 authored by Nikolai Kosjar's avatar Nikolai Kosjar
Browse files

C++: Introduce caches to Clone* classes



Done-with: Erik Verbruggen <erik.verbruggen@digia.com>
Task-number: QTCREATORBUG-8747

Change-Id: I7cb694f8180c6aa932b07066d98d095340111324
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
Reviewed-by: xSacha
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@digia.com>
parent 2a74ec4f
......@@ -39,12 +39,18 @@ CloneType::CloneType(Clone *clone)
FullySpecifiedType CloneType::cloneType(const FullySpecifiedType &type, Subst *subst)
{
TypeSubstPair typeSubstPair = std::make_pair(type, subst);
if (_cache.find(typeSubstPair) != _cache.end())
return _cache[typeSubstPair];
std::swap(_subst, subst);
FullySpecifiedType ty(type);
std::swap(_type, ty);
accept(_type.type());
std::swap(_type, ty);
std::swap(_subst, subst);
_cache[typeSubstPair] = ty;
return ty;
}
......@@ -179,13 +185,22 @@ Symbol *CloneSymbol::cloneSymbol(Symbol *symbol, Subst *subst)
if (! symbol)
return 0;
SymbolSubstPair symbolSubstPair = std::make_pair(symbol, subst);
if (_cache.find(symbolSubstPair) != _cache.end()) {
Symbol *cachedSymbol = _cache[symbolSubstPair];
if (cachedSymbol->scope() == symbol->scope())
return cachedSymbol;
}
Symbol *r = 0;
std::swap(_subst, subst);
std::swap(_symbol, r);
accept(symbol);
std::swap(_symbol, r);
std::swap(_subst, subst);
CPP_CHECK(r != 0);
_cache[symbolSubstPair] = r;
return r;
}
......@@ -394,6 +409,10 @@ const Name *CloneName::cloneName(const Name *name, Subst *subst)
if (! name)
return 0;
NameSubstPair nameSubstPair = std::make_pair(name, subst);
if (_cache.find(nameSubstPair) != _cache.end())
return _cache[nameSubstPair];
const Name *r = 0;
std::swap(_subst, subst);
std::swap(_name, r);
......@@ -401,6 +420,7 @@ const Name *CloneName::cloneName(const Name *name, Subst *subst)
std::swap(_name, r);
std::swap(_subst, subst);
CPP_CHECK(r != 0);
_cache[nameSubstPair] = r;
return r;
}
......
......@@ -27,7 +27,9 @@
#include "Name.h"
#include "NameVisitor.h"
#include "SymbolVisitor.h"
#include <map>
#include <utility>
namespace CPlusPlus {
......@@ -93,6 +95,9 @@ protected:
virtual void visit(ObjCForwardProtocolDeclaration *type);
protected:
typedef std::pair <const FullySpecifiedType, Subst *> TypeSubstPair;
std::map<TypeSubstPair, FullySpecifiedType> _cache;
Clone *_clone;
Control *_control;
Subst *_subst;
......@@ -118,6 +123,9 @@ protected:
virtual void visit(const SelectorNameId *name);
protected:
typedef std::pair <const Name *, Subst *> NameSubstPair;
std::map<NameSubstPair, const Name *> _cache;
Clone *_clone;
Control *_control;
Subst *_subst;
......@@ -163,6 +171,9 @@ protected:
virtual bool visit(ObjCPropertyDeclaration *symbol);
protected:
typedef std::pair <Symbol *, Subst *> SymbolSubstPair;
std::map<SymbolSubstPair, Symbol *> _cache;
Clone *_clone;
Control *_control;
Subst *_subst;
......
......@@ -1160,7 +1160,8 @@ void ClassOrNamespace::NestedClassInstantiator::instantiate(ClassOrNamespace *en
foreach (Symbol *s, nestedClassOrNamespace->_symbols) {
Symbol *clone = _cloner.symbol(s, &_subst);
clone->setScope(s->scope());
if (!clone->enclosingScope()) // Not from the cache but just cloned.
clone->setScope(s->enclosingScope());
nestedClassOrNamespaceInstantiation->_symbols.append(clone);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment