Skip to content

Commit c004f5c

Browse files
committed
[SourceKit] Change RenameRangeCollector::startSourceEntity to use early returns
1 parent 1f6678a commit c004f5c

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

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)