@@ -1846,21 +1846,40 @@ class FormatWalker: public ide::SourceEntityWalker {
1846
1846
SourceLoc FoundSibling;
1847
1847
SourceManager &SM;
1848
1848
std::vector<Token> &Tokens;
1849
- std::vector<SourceLoc> TokenLocs;
1850
1849
SourceLoc &TargetLoc;
1851
1850
TokenIt TI;
1852
1851
bool NeedExtraIndentation;
1853
1852
1853
+ class SourceLocIterator : public std ::iterator<std::input_iterator_tag,
1854
+ SourceLoc>
1855
+ {
1856
+ TokenIt It;
1857
+ public:
1858
+ SourceLocIterator (TokenIt It) :It(It) {}
1859
+ SourceLocIterator (const SourceLocIterator& mit) : It(mit.It) {}
1860
+ SourceLocIterator& operator ++() {++It; return *this ;}
1861
+ SourceLocIterator operator ++(int ) {
1862
+ SourceLocIterator tmp (*this );
1863
+ operator ++();
1864
+ return tmp;
1865
+ }
1866
+ bool operator ==(const SourceLocIterator& rhs) {return It==rhs.It ;}
1867
+ bool operator !=(const SourceLocIterator& rhs) {return It!=rhs.It ;}
1868
+ SourceLoc operator *() {return It->getLoc ();}
1869
+ };
1870
+
1854
1871
void adjustTokenIteratorToImmediateAfter (SourceLoc End) {
1855
- auto Lower = std::lower_bound (TokenLocs.begin (), TokenLocs.end (), End,
1872
+ SourceLocIterator LocBegin (Tokens.begin ());
1873
+ SourceLocIterator LocEnd (Tokens.end ());
1874
+ auto Lower = std::lower_bound (LocBegin, LocEnd, End,
1856
1875
[&](SourceLoc L, SourceLoc R) {
1857
1876
return SM.isBeforeInBuffer (L, R);
1858
1877
});
1859
1878
if (*Lower == End) {
1860
1879
Lower ++;
1861
1880
}
1862
1881
TI = Tokens.begin ();
1863
- std::advance (TI, Lower - TokenLocs. begin ( ));
1882
+ std::advance (TI, std::distance (LocBegin, Lower ));
1864
1883
}
1865
1884
1866
1885
bool isImmediateAfterSeparator (SourceLoc End, tok Separator) {
@@ -1892,11 +1911,7 @@ class FormatWalker: public ide::SourceEntityWalker {
1892
1911
SiblingCollector (SourceManager &SM, std::vector<Token> &Tokens,
1893
1912
SourceLoc &TargetLoc) : SM(SM), Tokens(Tokens),
1894
1913
TargetLoc (TargetLoc), TI(Tokens.begin()),
1895
- NeedExtraIndentation(false ) {
1896
- for (Token &T : Tokens) {
1897
- TokenLocs.push_back (T.getLoc ());
1898
- }
1899
- }
1914
+ NeedExtraIndentation(false ) {}
1900
1915
1901
1916
void collect (ASTNode Node) {
1902
1917
if (FoundSibling.isValid ())
0 commit comments