forked from qt-creator/qt-creator
CppTools: Speed up TypeHierarchyBuilder::buildDerived()
Depending files of the file the base class is defined in were look up
for *all* the derived classes. With this change, only the relevant files
for the 'current' base class are looked up.
Tested with qtbase.pro via Ctrl+T on the QObject definition.
- Without this patch: ~60s
- With this patch: ~40s
Change-Id: Ia947f1a4f7d242a0cb81e42d0ef2afab2db70a7f
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
This commit is contained in:
@@ -143,11 +143,8 @@ const QList<TypeHierarchy> &TypeHierarchy::hierarchy() const
|
||||
TypeHierarchyBuilder::TypeHierarchyBuilder(CPlusPlus::Symbol *symbol, const CPlusPlus::Snapshot &snapshot)
|
||||
: _symbol(symbol)
|
||||
, _snapshot(snapshot)
|
||||
, _dependencies(QString::fromUtf8(symbol->fileName(), symbol->fileNameLength()))
|
||||
{
|
||||
CPlusPlus::DependencyTable dependencyTable;
|
||||
dependencyTable.build(_snapshot);
|
||||
_dependencies.append(dependencyTable.filesDependingOn(_dependencies.first()));
|
||||
_dependencyTable.build(_snapshot);
|
||||
}
|
||||
|
||||
void TypeHierarchyBuilder::reset()
|
||||
@@ -160,11 +157,12 @@ TypeHierarchy TypeHierarchyBuilder::buildDerivedTypeHierarchy()
|
||||
{
|
||||
reset();
|
||||
TypeHierarchy hierarchy(_symbol);
|
||||
buildDerived(&hierarchy);
|
||||
buildDerived(&hierarchy, filesDependingOn(_symbol));
|
||||
return hierarchy;
|
||||
}
|
||||
|
||||
void TypeHierarchyBuilder::buildDerived(TypeHierarchy *typeHierarchy)
|
||||
void TypeHierarchyBuilder::buildDerived(TypeHierarchy *typeHierarchy,
|
||||
const QStringList &dependingFiles)
|
||||
{
|
||||
CPlusPlus::Symbol *symbol = typeHierarchy->_symbol;
|
||||
if (_visited.contains(symbol))
|
||||
@@ -175,7 +173,7 @@ void TypeHierarchyBuilder::buildDerived(TypeHierarchy *typeHierarchy)
|
||||
const QString &symbolName = _overview.prettyName(CPlusPlus::LookupContext::fullyQualifiedName(symbol));
|
||||
DerivedHierarchyVisitor visitor(symbolName);
|
||||
|
||||
foreach (const QString &fileName, _dependencies) {
|
||||
foreach (const QString &fileName, dependingFiles) {
|
||||
CPlusPlus::Document::Ptr doc = _snapshot.document(fileName);
|
||||
if ((_candidates.contains(fileName) && !_candidates.value(fileName).contains(symbolName))
|
||||
|| !doc->control()->findIdentifier(symbol->identifier()->chars(),
|
||||
@@ -191,8 +189,17 @@ void TypeHierarchyBuilder::buildDerived(TypeHierarchy *typeHierarchy)
|
||||
|
||||
foreach (CPlusPlus::Symbol *s, visitor.derived()) {
|
||||
TypeHierarchy derivedHierarchy(s);
|
||||
buildDerived(&derivedHierarchy);
|
||||
buildDerived(&derivedHierarchy, filesDependingOn(s));
|
||||
typeHierarchy->_hierarchy.append(derivedHierarchy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QStringList TypeHierarchyBuilder::filesDependingOn(CPlusPlus::Symbol *symbol) const
|
||||
{
|
||||
if (!symbol)
|
||||
return QStringList();
|
||||
|
||||
const QString file = QString::fromUtf8(symbol->fileName(), symbol->fileNameLength());
|
||||
return QStringList() << file << _dependencyTable.filesDependingOn(file);
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
#include "cpptools_global.h"
|
||||
#include "cppmodelmanagerinterface.h"
|
||||
|
||||
#include <cplusplus/DependencyTable.h>
|
||||
#include <cplusplus/Overview.h>
|
||||
|
||||
#include <QList>
|
||||
@@ -66,14 +67,15 @@ public:
|
||||
|
||||
private:
|
||||
void reset();
|
||||
void buildDerived(TypeHierarchy *typeHierarchy);
|
||||
void buildDerived(TypeHierarchy *typeHierarchy, const QStringList &dependencies);
|
||||
QStringList filesDependingOn(CPlusPlus::Symbol *symbol) const;
|
||||
|
||||
CPlusPlus::Symbol *_symbol;
|
||||
CPlusPlus::Snapshot _snapshot;
|
||||
QStringList _dependencies;
|
||||
QSet<CPlusPlus::Symbol *> _visited;
|
||||
QHash<QString, QSet<QString> > _candidates;
|
||||
CPlusPlus::Overview _overview;
|
||||
CPlusPlus::DependencyTable _dependencyTable;
|
||||
};
|
||||
|
||||
} // CppTools
|
||||
|
||||
Reference in New Issue
Block a user