djasper added a comment. I experimented a bit. What do you think of this?
================ Comment at: lib/Format/Format.cpp:1822 @@ +1821,3 @@ + cleanupRight(Line->First, Line->Last, tok::comma, tok::comma); + checkConstructorInitList(*Line); + } ---------------- You could turn this into: for (auto &Line : AnnotatedLines) { if (Line->Affected) { cleanupRight(Line->First, tok::comma, tok::comma); cleanupRight(Line->First, TT_CtorInitializerColon, tok::comma); cleanupLeft(Line->First, tok::comma, tok::l_brace); cleanupLeft(Line->First, TT_CtorInitializerColon, tok::l_brace); } } ================ Comment at: lib/Format/Format.cpp:1914 @@ -1906,1 +1913,3 @@ + FormatToken *getNextTokenNotDeletedUntilEnd(const FormatToken *Tok, + const FormatToken *End, ---------------- And all of this into: // Checks pairs {start, start->next},..., {end->previous, end} and deletes one // of the token in the pair if the left token has \p LK token kind and the // right token has \p RK token kind. If \p DeleteLeft is true, the left token // is deleted on match; otherwise, the right token is deleted. template <typename LeftKind, typename RightKind> void cleanupPair(FormatToken *Start, LeftKind LK, RightKind RK, bool DeleteLeft) { auto NextNotDeleted = [this](const FormatToken &Tok) -> FormatToken * { for (auto *Res = Tok.Next; Res; Res = Res->Next) if (!Res->is(tok::comment) && DeletedTokens.find(Res) == DeletedTokens.end()) return Res; return nullptr; }; for (auto *Left = Start; Left;) { auto *Right = NextNotDeleted(*Left); if (!Right) break; if (Left->is(LK) && Right->is(RK)) { deleteToken(DeleteLeft ? Left : Right); // If the right token is deleted, we should keep the left token // unchanged and pair it with the new right token. if (!DeleteLeft) continue; } Left = Right; } } template <typename LeftKind, typename RightKind> void cleanupLeft(FormatToken *Start, LeftKind LK, RightKind RK) { cleanupPair(Start, LK, RK, /*DeleteLeft=*/true); } template <typename LeftKind, typename RightKind> void cleanupRight(FormatToken *Start, LeftKind LK, RightKind RK) { cleanupPair(Start, LK, RK, /*DeleteLeft=*/false); } http://reviews.llvm.org/D19804 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits