forked from qt-creator/qt-creator
Clang: Add file cache
The database is using file path integer ids to handle file paths because otherwise we would save many redundant data. This patch is improving it further with the introduction of a database based file path cache. The entries are now divided in a directory path and file name. This is quite handy for directory based file watching. Change-Id: I03f2e388e43f3d521d6bf8e39dfb95eb2309dc73 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
This commit is contained in:
@@ -27,6 +27,7 @@
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
|
||||
#include <filepathid.h>
|
||||
#include <sourcelocations.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -39,68 +40,20 @@ class SymbolQuery
|
||||
using ReadStatement = typename StatementFactory::ReadStatementType;
|
||||
|
||||
public:
|
||||
using Location = SourceLocations::Location;
|
||||
using Source = SourceLocations::Source;
|
||||
|
||||
SymbolQuery(StatementFactory &statementFactory)
|
||||
: m_statementFactory(statementFactory)
|
||||
{}
|
||||
|
||||
SourceLocations locationsAt(const Utils::PathString &filePath, uint line, uint utf8Column)
|
||||
SourceLocations locationsAt(ClangBackEnd::FilePathId filePathId, int line, int utf8Column)
|
||||
{
|
||||
ReadStatement &locationsStatement = m_statementFactory.selectLocationsForSymbolLocation;
|
||||
|
||||
const std::size_t reserveSize = 128;
|
||||
|
||||
auto locations = locationsStatement.template values<Location, 3>(
|
||||
reserveSize,
|
||||
filePath,
|
||||
line,
|
||||
utf8Column);
|
||||
|
||||
const std::vector<qint64> sourceIds = uniqueSourceIds(locations);
|
||||
|
||||
ReadStatement &sourcesStatement = m_statementFactory.selectSourcePathForId;
|
||||
|
||||
auto sources = sourcesStatement.template values<Source, 2>(
|
||||
reserveSize,
|
||||
sourceIds);
|
||||
|
||||
return {locations, sourcesToHashMap(sources)};
|
||||
}
|
||||
|
||||
static
|
||||
qint64 sourceId(const Location &location)
|
||||
{
|
||||
return location.sourceId;
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<qint64> uniqueSourceIds(const std::vector<Location> &locations)
|
||||
{
|
||||
std::vector<qint64> ids;
|
||||
ids.reserve(locations.size());
|
||||
|
||||
std::transform(locations.begin(),
|
||||
locations.end(),
|
||||
std::back_inserter(ids),
|
||||
sourceId);
|
||||
|
||||
auto newEnd = std::unique(ids.begin(), ids.end());
|
||||
ids.erase(newEnd, ids.end());
|
||||
|
||||
return ids;
|
||||
}
|
||||
|
||||
static
|
||||
std::unordered_map<qint64, Utils::PathString> sourcesToHashMap(const std::vector<Source> &sources)
|
||||
{
|
||||
std::unordered_map<qint64, Utils::PathString> dictonary;
|
||||
|
||||
for (const Source &source : sources)
|
||||
dictonary.emplace(source.sourceId, std::move(source.sourcePath));
|
||||
|
||||
return dictonary;
|
||||
return locationsStatement.template values<SourceLocation, 4>(reserveSize,
|
||||
filePathId.fileNameId,
|
||||
line,
|
||||
utf8Column);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user