src: Improved code view snippet generation performance
This commit is contained in:
@@ -1118,21 +1118,23 @@ std::vector<Id> PersistentStorage::getActiveTokenIdsForId(Id tokenId, Id* declar
|
||||
|
||||
std::vector<Id> activeTokenIds;
|
||||
|
||||
if (!(m_sqliteIndexStorage.isEdge(tokenId) || m_sqliteIndexStorage.isNode(tokenId)))
|
||||
bool isNode = m_sqliteIndexStorage.isNode(tokenId);
|
||||
bool isEdge = m_sqliteIndexStorage.isEdge(tokenId);
|
||||
|
||||
if (!isEdge && !isNode)
|
||||
{
|
||||
return activeTokenIds;
|
||||
}
|
||||
|
||||
activeTokenIds.push_back(tokenId);
|
||||
|
||||
if (m_sqliteIndexStorage.isNode(tokenId))
|
||||
if (isNode)
|
||||
{
|
||||
*declarationId = tokenId;
|
||||
|
||||
const std::vector<StorageEdge> incomingEdges = m_sqliteIndexStorage.getEdgesByTargetId(tokenId);
|
||||
for (size_t i = 0; i < incomingEdges.size(); i++)
|
||||
for (const StorageEdge& edge : m_sqliteIndexStorage.getEdgesByTargetId(tokenId))
|
||||
{
|
||||
activeTokenIds.push_back(incomingEdges[i].id);
|
||||
activeTokenIds.push_back(edge.id);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1247,42 +1249,44 @@ std::shared_ptr<SourceLocationCollection> PersistentStorage::getSourceLocationsF
|
||||
|
||||
for (const StorageSourceLocation& sourceLocation: m_sqliteIndexStorage.getAllByIds<StorageSourceLocation>(locationIds))
|
||||
{
|
||||
auto it = locationIdToElementIdMap.find(sourceLocation.id);
|
||||
if (it != locationIdToElementIdMap.end())
|
||||
const LocationType type = intToLocationType(sourceLocation.type);
|
||||
if (type == LOCATION_QUALIFIER)
|
||||
{
|
||||
const LocationType type = intToLocationType(sourceLocation.type);
|
||||
if (type == LOCATION_QUALIFIER)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
FilePath path = getFileNodePath(sourceLocation.fileNodeId);
|
||||
if (path.empty())
|
||||
auto it = locationIdToElementIdMap.find(sourceLocation.id);
|
||||
if (it == locationIdToElementIdMap.end())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
FilePath path = getFileNodePath(sourceLocation.fileNodeId);
|
||||
if (path.empty())
|
||||
{
|
||||
const StorageNode fileNode = m_sqliteIndexStorage.getNodeById(sourceLocation.fileNodeId);
|
||||
if (fileNode.id)
|
||||
{
|
||||
const StorageNode fileNode = m_sqliteIndexStorage.getNodeById(sourceLocation.fileNodeId);
|
||||
if (fileNode.id)
|
||||
const FilePath path2 = FilePath(NameHierarchy::deserialize(fileNode.serializedName).getQualifiedName());
|
||||
if (path2.exists())
|
||||
{
|
||||
const FilePath path2 = FilePath(NameHierarchy::deserialize(fileNode.serializedName).getQualifiedName());
|
||||
if (path2.exists())
|
||||
{
|
||||
path = path2;
|
||||
}
|
||||
path = path2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!path.empty())
|
||||
{
|
||||
collection->addSourceLocation(
|
||||
type,
|
||||
sourceLocation.id,
|
||||
std::vector<Id>(1, it->second),
|
||||
path,
|
||||
sourceLocation.startLine,
|
||||
sourceLocation.startCol,
|
||||
sourceLocation.endLine,
|
||||
sourceLocation.endCol
|
||||
);
|
||||
}
|
||||
if (!path.empty())
|
||||
{
|
||||
collection->addSourceLocation(
|
||||
type,
|
||||
sourceLocation.id,
|
||||
std::vector<Id>(1, it->second),
|
||||
path,
|
||||
sourceLocation.startLine,
|
||||
sourceLocation.startCol,
|
||||
sourceLocation.endLine,
|
||||
sourceLocation.endCol
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1333,12 +1337,22 @@ std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForFile
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsForLinesInFile(
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
const FilePath& filePath, size_t startLine, size_t endLine
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return getSourceLocationsForFile(filePath)->getFilteredByLines(firstLineNumber, lastLineNumber);
|
||||
return m_sqliteIndexStorage.getSourceLocationsForLinesInFile(
|
||||
filePath, startLine, endLine)->getFilteredByLines(startLine, endLine);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getSourceLocationsOfTypeInFile(
|
||||
const FilePath& filePath, LocationType type
|
||||
) const
|
||||
{
|
||||
TRACE();
|
||||
|
||||
return m_sqliteIndexStorage.getSourceLocationsOfTypeInFile(filePath, type);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> PersistentStorage::getCommentLocationsInFile(const FilePath& filePath) const
|
||||
|
||||
@@ -109,8 +109,9 @@ public:
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const override;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const FilePath& filePath, uint firstLineNumber, uint lastLineNumber
|
||||
) const override;
|
||||
const FilePath& filePath, size_t startLine, size_t endLine) const override;
|
||||
virtual std::shared_ptr<SourceLocationFile> getSourceLocationsOfTypeInFile(
|
||||
const FilePath& filePath, LocationType type) const override;
|
||||
|
||||
virtual std::shared_ptr<SourceLocationFile> getCommentLocationsInFile(const FilePath& filePath) const override;
|
||||
|
||||
|
||||
@@ -643,7 +643,8 @@ void SqliteIndexStorage::setNodeType(int type, Id nodeId)
|
||||
);
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFile(const FilePath& filePath) const
|
||||
std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFile(
|
||||
const FilePath& filePath, const std::string& query) const
|
||||
{
|
||||
std::shared_ptr<SourceLocationFile> ret = std::make_shared<SourceLocationFile>(filePath, true, false);
|
||||
|
||||
@@ -658,7 +659,7 @@ std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFil
|
||||
std::vector<Id> sourceLocationIds;
|
||||
std::unordered_map<Id, StorageSourceLocation> sourceLocationIdToData;
|
||||
for (const StorageSourceLocation& storageLocation:
|
||||
doGetAll<StorageSourceLocation>("WHERE file_node_id == " + std::to_string(file.id)))
|
||||
doGetAll<StorageSourceLocation>("WHERE file_node_id == " + std::to_string(file.id) + " " + query))
|
||||
{
|
||||
sourceLocationIds.push_back(storageLocation.id);
|
||||
sourceLocationIdToData[storageLocation.id] = storageLocation;
|
||||
@@ -690,6 +691,19 @@ std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForFil
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsForLinesInFile(
|
||||
const FilePath& filePath, size_t startLine, size_t endLine) const
|
||||
{
|
||||
return getSourceLocationsForFile(filePath,
|
||||
"AND start_line <= " + std::to_string(endLine) + " AND end_line >= " + std::to_string(startLine));
|
||||
}
|
||||
|
||||
std::shared_ptr<SourceLocationFile> SqliteIndexStorage::getSourceLocationsOfTypeInFile(
|
||||
const FilePath& filePath, LocationType type) const
|
||||
{
|
||||
return getSourceLocationsForFile(filePath, "AND type == " + std::to_string(locationTypeToInt(type)));
|
||||
}
|
||||
|
||||
std::vector<StorageOccurrence> SqliteIndexStorage::getOccurrencesForLocationId(Id locationId) const
|
||||
{
|
||||
std::vector<Id> locationIds {locationId};
|
||||
@@ -779,6 +793,10 @@ std::vector<std::pair<int, SqliteDatabaseIndex>> SqliteIndexStorage::getIndices(
|
||||
STORAGE_MODE_READ | STORAGE_MODE_CLEAR,
|
||||
SqliteDatabaseIndex("source_location_file_node_id_index", "source_location(file_node_id)")
|
||||
));
|
||||
indices.push_back(std::make_pair(
|
||||
STORAGE_MODE_READ,
|
||||
SqliteDatabaseIndex("source_location_file_node_id_type_index", "source_location(file_node_id, type)")
|
||||
));
|
||||
indices.push_back(std::make_pair(
|
||||
STORAGE_MODE_WRITE,
|
||||
SqliteDatabaseIndex("source_location_all_data_index", "source_location(file_node_id, start_line, start_column, end_line, end_column, type)")
|
||||
|
||||
@@ -88,7 +88,12 @@ public:
|
||||
void setFileComplete(bool complete, Id fileId);
|
||||
void setNodeType(int type, Id nodeId);
|
||||
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(const FilePath& filePath) const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationsForFile(
|
||||
const FilePath& filePath, const std::string& query = "") const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationsForLinesInFile(
|
||||
const FilePath& filePath, size_t startLine, size_t endLine) const;
|
||||
std::shared_ptr<SourceLocationFile> getSourceLocationsOfTypeInFile(
|
||||
const FilePath& filePath, LocationType type) const;
|
||||
|
||||
std::vector<StorageOccurrence> getOccurrencesForLocationId(Id locationId) const;
|
||||
std::vector<StorageOccurrence> getOccurrencesForLocationIds(const std::vector<Id>& locationIds) const;
|
||||
|
||||
Reference in New Issue
Block a user