Commit 600f4438 authored by Przemyslaw Gorszkowski's avatar Przemyslaw Gorszkowski Committed by Erik Verbruggen
Browse files

C++: performance improvement for template instantiation



Add cache for instantiated instantiations in base template class.

Change-Id: I5c457ea4dfeab72cc3910f0092ca1bc14b8aa1ac
Reviewed-by: default avatarErik Verbruggen <erik.verbruggen@digia.com>
parent 9a556a61
...@@ -749,6 +749,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -749,6 +749,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
return 0; return 0;
ClassOrNamespace *reference = it->second; ClassOrNamespace *reference = it->second;
ClassOrNamespace *baseTemplateClassReference = reference;
const TemplateNameId *templId = name->asTemplateNameId(); const TemplateNameId *templId = name->asTemplateNameId();
if (templId) { if (templId) {
...@@ -764,7 +765,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -764,7 +765,8 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
if (templId->isSpecialization()) { if (templId->isSpecialization()) {
// if it is a specialization we try to find or create new one and // if it is a specialization we try to find or create new one and
// add to base class(reference) // add to base class(reference)
TemplateNameIdTable::const_iterator cit = reference->_specializations.find(templId); TemplateNameIdTable::const_iterator cit
= reference->_specializations.find(templId);
if (cit != reference->_specializations.end()) { if (cit != reference->_specializations.end()) {
return cit->second; return cit->second;
} else { } else {
...@@ -776,6 +778,10 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -776,6 +778,10 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
return newSpecialization; return newSpecialization;
} }
} else { } else {
QMap<const TemplateNameId *, ClassOrNamespace *>::const_iterator citInstantiation
= reference->_instantiations.find(templId);
if (citInstantiation != reference->_instantiations.end())
return citInstantiation.value();
TemplateNameId *nonConstTemplId = const_cast<TemplateNameId *>(templId); TemplateNameId *nonConstTemplId = const_cast<TemplateNameId *>(templId);
// make this instantiation looks like specialization which help to find // make this instantiation looks like specialization which help to find
// full specialization for this instantiation // full specialization for this instantiation
...@@ -833,7 +839,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -833,7 +839,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
// construct all instantiation data. // construct all instantiation data.
if (templId) { if (templId) {
_alreadyConsideredTemplates.insert(templId); _alreadyConsideredTemplates.insert(templId);
ClassOrNamespace *instantiation = _factory->allocClassOrNamespace(reference); ClassOrNamespace *instantiation = _factory->allocClassOrNamespace(baseTemplateClassReference);
#ifdef DEBUG_LOOKUP #ifdef DEBUG_LOOKUP
instantiation->_name = templId; instantiation->_name = templId;
#endif // DEBUG_LOOKUP #endif // DEBUG_LOOKUP
...@@ -960,6 +966,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac ...@@ -960,6 +966,7 @@ ClassOrNamespace *ClassOrNamespace::nestedType(const Name *name, ClassOrNamespac
} }
_alreadyConsideredTemplates.clear(templId); _alreadyConsideredTemplates.clear(templId);
baseTemplateClassReference->_instantiations[templId] = instantiation;
return instantiation; return instantiation;
} }
......
...@@ -113,6 +113,7 @@ private: ...@@ -113,6 +113,7 @@ private:
QList<Symbol *> _todo; QList<Symbol *> _todo;
QSharedPointer<Control> _control; QSharedPointer<Control> _control;
TemplateNameIdTable _specializations; TemplateNameIdTable _specializations;
QMap<const TemplateNameId *, ClassOrNamespace *> _instantiations;
// it's an instantiation. // it's an instantiation.
const TemplateNameId *_templateId; const TemplateNameId *_templateId;
......
Supports Markdown
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