Skip to content

Commit 38d2b96

Browse files
committed
[NFC] Small Index.cpp cleanups
1 parent 453fd22 commit 38d2b96

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

include/swift/Index/IndexSymbol.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ struct IndexSymbol : IndexRelation {
6565
SmallVector<IndexRelation, 3> Relations;
6666
unsigned line = 0;
6767
unsigned column = 0;
68-
Optional<unsigned> offset;
6968

7069
IndexSymbol() = default;
7170

lib/Index/Index.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
834834
return true;
835835

836836
IndexSymbol Info;
837-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
837+
std::tie(Info.line, Info.column) = getLineCol(Loc);
838838
Info.roles |= (unsigned)SymbolRole::Reference;
839839
Info.symInfo = getSymbolInfoForModule(Mod);
840840
getModuleNameAndUSR(Mod, Info.name, Info.USR);
@@ -949,13 +949,10 @@ class IndexSwiftASTWalker : public SourceEntityWalker {
949949

950950
bool indexComment(const Decl *D);
951951

952-
std::tuple<unsigned, unsigned, Optional<unsigned>>
953-
getLineColAndOffset(SourceLoc Loc) {
952+
std::pair<unsigned, unsigned> getLineCol(SourceLoc Loc) {
954953
if (Loc.isInvalid())
955-
return std::make_tuple(0, 0, None);
956-
auto lineAndColumn = SrcMgr.getLineAndColumnInBuffer(Loc, BufferID);
957-
unsigned offset = SrcMgr.getLocOffsetInBuffer(Loc, BufferID);
958-
return std::make_tuple(lineAndColumn.first, lineAndColumn.second, offset);
954+
return std::make_pair(0, 0);
955+
return SrcMgr.getLineAndColumnInBuffer(Loc, BufferID);
959956
}
960957

961958
bool shouldIndex(ValueDecl *D, bool IsRef) const {
@@ -1618,23 +1615,21 @@ bool IndexSwiftASTWalker::initIndexSymbol(ValueDecl *D, SourceLoc Loc,
16181615

16191616
// Cannot be extension, which is not a ValueDecl.
16201617

1618+
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
1619+
return true;
1620+
std::tie(Info.line, Info.column) = getLineCol(Loc);
1621+
16211622
if (IsRef) {
16221623
Info.roles |= (unsigned)SymbolRole::Reference;
16231624
addContainedByRelationIfContained(Info);
16241625
} else {
16251626
Info.roles |= (unsigned)SymbolRole::Definition;
16261627
if (D->isImplicit())
16271628
Info.roles |= (unsigned)SymbolRole::Implicit;
1628-
}
1629-
1630-
if (getNameAndUSR(D, /*ExtD=*/nullptr, Info.name, Info.USR))
1631-
return true;
1632-
1633-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
1634-
if (!IsRef) {
16351629
if (auto Group = D->getGroupName())
16361630
Info.group = Group.getValue();
16371631
}
1632+
16381633
return false;
16391634
}
16401635

@@ -1651,7 +1646,7 @@ bool IndexSwiftASTWalker::initIndexSymbol(ExtensionDecl *ExtD, ValueDecl *Extend
16511646
if (getNameAndUSR(ExtendedD, ExtD, Info.name, Info.USR))
16521647
return true;
16531648

1654-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(Loc);
1649+
std::tie(Info.line, Info.column) = getLineCol(Loc);
16551650
if (auto Group = ExtD->getGroupName())
16561651
Info.group = Group.getValue();
16571652
return false;
@@ -1786,7 +1781,7 @@ bool IndexSwiftASTWalker::indexComment(const Decl *D) {
17861781
OS << "t:" << tagName;
17871782
Info.USR = stringStorage.copyString(OS.str());
17881783
}
1789-
std::tie(Info.line, Info.column, Info.offset) = getLineColAndOffset(loc);
1784+
std::tie(Info.line, Info.column) = getLineCol(loc);
17901785
if (!IdxConsumer.startSourceEntity(Info) || !IdxConsumer.finishSourceEntity(Info.symInfo, Info.roles)) {
17911786
Cancelled = true;
17921787
break;

0 commit comments

Comments
 (0)