Skip to content

Commit 3e5a772

Browse files
committed
[SourceKit] Change RenameRangeCollector::startSourceEntity to use early returns
1 parent 6d332ac commit 3e5a772

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

include/swift/Refactoring/RenameLoc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ struct RenameLoc {
5353
/// The column at which the base name (excluding trivia) starts (1-based).
5454
unsigned Column;
5555

56-
/// /// The offset at which the related name starts.
56+
/// The offset at which the related name starts.
5757
unsigned Offset;
5858

5959
/// The length of the base name in the related identifier. For functions,

lib/Refactoring/LocalRename.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,25 @@ class RenameRangeCollector : public IndexDataConsumer {
207207
bool finishDependency(bool isClangModule) override { return true; }
208208

209209
Action startSourceEntity(const IndexSymbol &symbol) override {
210-
if (symbol.USR == usr) {
211-
if (auto loc = indexSymbolToRenameLoc(symbol)) {
212-
// Inside capture lists like `{ [test] in }`, 'test' refers to both the
213-
// newly declared, captured variable and the referenced variable it is
214-
// initialized from. Make sure to only rename it once.
215-
auto existingLoc = llvm::find_if(locations, [&](RenameLoc searchLoc) {
216-
return searchLoc.Line == loc->Line && searchLoc.Column == loc->Column;
217-
});
218-
if (existingLoc == locations.end()) {
219-
locations.push_back(std::move(*loc));
220-
} else {
221-
assert(existingLoc->OldName == loc->OldName &&
222-
"Asked to do a different rename for the same location?");
223-
}
224-
}
210+
if (symbol.USR != usr) {
211+
return IndexDataConsumer::Continue;
212+
}
213+
auto loc = indexSymbolToRenameLoc(symbol);
214+
if (!loc) {
215+
return IndexDataConsumer::Continue;
216+
}
217+
218+
// Inside capture lists like `{ [test] in }`, 'test' refers to both the
219+
// newly declared, captured variable and the referenced variable it is
220+
// initialized from. Make sure to only rename it once.
221+
auto existingLoc = llvm::find_if(locations, [&](RenameLoc searchLoc) {
222+
return searchLoc.Line == loc->Line && searchLoc.Column == loc->Column;
223+
});
224+
if (existingLoc == locations.end()) {
225+
locations.push_back(std::move(*loc));
226+
} else {
227+
assert(existingLoc->OldName == loc->OldName &&
228+
"Asked to do a different rename for the same location?");
225229
}
226230
return IndexDataConsumer::Continue;
227231
}

0 commit comments

Comments
 (0)