Skip to content

Commit 89f89ab

Browse files
committed
Make symbol info only store symbol occurrence offset, not start/end offset. The rest can be determined from the source manager by finding the token's SourceLoc.
1 parent 39e43d7 commit 89f89ab

File tree

2 files changed

+8
-19
lines changed

2 files changed

+8
-19
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ struct IndexSymbol : IndexRelation {
6666
SmallVector<IndexRelation, 3> Relations;
6767
unsigned line = 0;
6868
unsigned column = 0;
69-
unsigned startOffset = 0;
70-
unsigned endOffset = 0;
69+
unsigned offset = 0;
7170

7271
IndexSymbol() = default;
7372

lib/Index/Index.cpp

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -474,8 +474,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
474474

475475
IndexSymbol Info;
476476
std::tie(Info.line, Info.column) = getLineCol(Loc);
477-
std::tie(Info.startOffset, Info.endOffset) =
478-
getRangeStartAndEndOffset(Range);
477+
Info.offset = getOffsetInBuffer(Loc);
479478
Info.roles |= (unsigned)SymbolRole::Reference;
480479
Info.symInfo = getSymbolInfoForModule(Mod);
481480
getModuleNameAndUSR(Mod, Info.name, Info.USR);
@@ -593,19 +592,10 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
593592
return SrcMgr.getLineAndColumn(Loc, BufferID);
594593
}
595594

596-
std::pair<unsigned, unsigned> getRangeStartAndEndOffset(CharSourceRange Range) {
597-
if (Range.isInvalid())
598-
return std::make_pair(0, 0);
599-
unsigned offset = SrcMgr.getLocOffsetInBuffer(Range.getStart(), BufferID);
600-
unsigned length = SrcMgr.getByteDistance(Range.getStart(), Range.getEnd());
601-
return std::make_pair(offset, offset + length);
602-
}
603-
604-
std::pair<unsigned, unsigned> getLocStartAndEndOffset(SourceLoc Loc) {
595+
unsigned getOffsetInBuffer(SourceLoc Loc) {
605596
if (Loc.isInvalid())
606-
return std::make_pair(0, 0);
607-
return getRangeStartAndEndOffset(
608-
Lexer::getCharSourceRangeFromSourceRange(SrcMgr, SourceRange(Loc)));
597+
return 0;
598+
return SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
609599
}
610600

611601
bool shouldIndex(ValueDecl *D, bool IsRef) const {
@@ -1243,7 +1233,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
12431233
return true;
12441234

12451235
std::tie(Info.line, Info.column) = getLineCol(Loc);
1246-
std::tie(Info.startOffset, Info.endOffset) = getLocStartAndEndOffset(Loc);
1236+
Info.offset = getOffsetInBuffer(Loc);
12471237
if (!IsRef) {
12481238
if (auto Group = D->getGroupName())
12491239
Info.group = Group.getValue();
@@ -1265,7 +1255,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
12651255
return true;
12661256

12671257
std::tie(Info.line, Info.column) = getLineCol(Loc);
1268-
std::tie(Info.startOffset, Info.endOffset) = getLocStartAndEndOffset(Loc);
1258+
Info.offset = getOffsetInBuffer(Loc);
12691259
if (auto Group = ExtD->getGroupName())
12701260
Info.group = Group.getValue();
12711261
return false;
@@ -1473,7 +1463,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
14731463
Info.USR = stringStorage.copyString(OS.str());
14741464
}
14751465
std::tie(Info.line, Info.column) = getLineCol(loc);
1476-
std::tie(Info.startOffset, Info.endOffset) = getLocStartAndEndOffset(loc);
1466+
Info.offset = getOffsetInBuffer(loc);
14771467
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
14781468
Cancelled = true;
14791469
break;

0 commit comments

Comments
 (0)