IDE: simplify some code. NFC (#11935)

* IDE: simplify some code. NFC

* add assert.
This commit is contained in:
Xi Ge
2017-09-14 18:19:48 -07:00
committed by GitHub
parent 2a582c4867
commit 2ba1ca2d8f
4 changed files with 31 additions and 27 deletions

View File

@@ -1257,13 +1257,7 @@ struct SimilarExprCollector: public SourceEntityWalker {
/// Find all tokens included by an expression.
llvm::ArrayRef<Token> getExprSlice(Expr *E) {
SourceLoc StartLoc = E->getStartLoc();
SourceLoc EndLoc = E->getEndLoc();
auto StartIt = token_lower_bound(AllTokens, StartLoc);
auto EndIt = token_lower_bound(AllTokens, EndLoc);
assert(StartIt->getLoc() == StartLoc);
assert(EndIt->getLoc() == EndLoc);
return AllTokens.slice(StartIt - AllTokens.begin(), EndIt - StartIt + 1);
return slice_token_array(AllTokens, E->getStartLoc(), E->getEndLoc());
}
SimilarExprCollector(SourceManager &SM, Expr* SelectedExpr,
@@ -1328,15 +1322,11 @@ bool RefactoringActionExtractExprBase::performChange() {
Collector.walk(BS);
if (ExtractRepeated) {
// Tokenize the brace statement; all expressions should have their tokens
// in this array.
auto AllTokens = TheFile->getAllTokens();
auto StartIt = token_lower_bound(AllTokens, BS->getStartLoc());
auto EndIt = token_lower_bound(AllTokens, BS->getEndLoc());
// Collect all expressions we are going to extract.
SimilarExprCollector(SM, SelectedExpr,
AllTokens.slice(StartIt - AllTokens.begin(), EndIt - StartIt + 1),
slice_token_array(TheFile->getAllTokens(),
BS->getStartLoc(),
BS->getEndLoc()),
AllExpressions).walk(BS);
} else {
AllExpressions.insert(SelectedExpr);