logic: Improved code view performance by removing duplicate TokenLocation check
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user