logic: Improved code view performance by removing duplicate TokenLocation check

This commit is contained in:
Eberhard Graether
2016-12-07 21:04:19 +01:00
parent a3428be65c
commit 6575485609
2 changed files with 6 additions and 32 deletions
+1 -1
View File
@@ -966,7 +966,7 @@ std::shared_ptr<TokenLocationCollection> PersistentStorage::getTokenLocationsFor
collection->addTokenLocation(
location.id,
occurrences.elementId,
m_sqliteStorage.getFileById(location.fileNodeId).filePath, // TODO: optimize: only once per file!
getFileNodePath(location.fileNodeId),
location.startLine,
location.startCol,
location.endLine,
+5 -31
View File
@@ -58,41 +58,15 @@ TokenLocation* TokenLocationFile::addTokenLocation(
{
TokenLocationLine* line = createTokenLocationLine(startLineNumber);
// Check if a TokenLocation with the same start and end was already added.
TokenLocation* start = nullptr;
line->forEachStartTokenLocation(
[&](TokenLocation* startLocation)
{
if (start)
{
return;
}
TokenLocation* start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber);
TokenLocation* endLocation = startLocation->getEndTokenLocation();
if (startLocation->getTokenId() == tokenId &&
startLocation->getColumnNumber() == startColumnNumber &&
endLocation &&
endLocation->getLineNumber() == endLineNumber &&
endLocation->getColumnNumber() == endColumnNumber)
{
start = startLocation;
}
}
);
if (!start)
if (startLineNumber != endLineNumber)
{
start = line->addStartTokenLocation(locationId, tokenId, startColumnNumber);
if (startLineNumber != endLineNumber)
{
line = createTokenLocationLine(endLineNumber);
}
line->addEndTokenLocation(start, endColumnNumber);
line = createTokenLocationLine(endLineNumber);
}
line->addEndTokenLocation(start, endColumnNumber);
return start;
}