[clang-format][NFC] Don't repeat Changes[i]/Changes[i - 1]

This commit is contained in:
Owen Pan 2024-04-27 15:10:48 -07:00
parent 6084dcbfce
commit b4af01bada

View File

@ -128,11 +128,13 @@ const tooling::Replacements &WhitespaceManager::generateReplacements() {
void WhitespaceManager::calculateLineBreakInformation() { void WhitespaceManager::calculateLineBreakInformation() {
Changes[0].PreviousEndOfTokenColumn = 0; Changes[0].PreviousEndOfTokenColumn = 0;
Change *LastOutsideTokenChange = &Changes[0]; Change *LastOutsideTokenChange = &Changes[0];
for (unsigned i = 1, e = Changes.size(); i != e; ++i) { for (unsigned I = 1, e = Changes.size(); I != e; ++I) {
auto &C = Changes[I];
auto &P = Changes[I - 1];
SourceLocation OriginalWhitespaceStart = SourceLocation OriginalWhitespaceStart =
Changes[i].OriginalWhitespaceRange.getBegin(); C.OriginalWhitespaceRange.getBegin();
SourceLocation PreviousOriginalWhitespaceEnd = SourceLocation PreviousOriginalWhitespaceEnd =
Changes[i - 1].OriginalWhitespaceRange.getEnd(); P.OriginalWhitespaceRange.getEnd();
unsigned OriginalWhitespaceStartOffset = unsigned OriginalWhitespaceStartOffset =
SourceMgr.getFileOffset(OriginalWhitespaceStart); SourceMgr.getFileOffset(OriginalWhitespaceStart);
unsigned PreviousOriginalWhitespaceEndOffset = unsigned PreviousOriginalWhitespaceEndOffset =
@ -167,31 +169,26 @@ void WhitespaceManager::calculateLineBreakInformation() {
// line of the token. // line of the token.
auto NewlinePos = Text.find_first_of('\n'); auto NewlinePos = Text.find_first_of('\n');
if (NewlinePos == StringRef::npos) { if (NewlinePos == StringRef::npos) {
Changes[i - 1].TokenLength = OriginalWhitespaceStartOffset - P.TokenLength = OriginalWhitespaceStartOffset -
PreviousOriginalWhitespaceEndOffset + PreviousOriginalWhitespaceEndOffset +
Changes[i].PreviousLinePostfix.size() + C.PreviousLinePostfix.size() + P.CurrentLinePrefix.size();
Changes[i - 1].CurrentLinePrefix.size();
} else { } else {
Changes[i - 1].TokenLength = P.TokenLength = NewlinePos + P.CurrentLinePrefix.size();
NewlinePos + Changes[i - 1].CurrentLinePrefix.size();
} }
// If there are multiple changes in this token, sum up all the changes until // If there are multiple changes in this token, sum up all the changes until
// the end of the line. // the end of the line.
if (Changes[i - 1].IsInsideToken && Changes[i - 1].NewlinesBefore == 0) { if (P.IsInsideToken && P.NewlinesBefore == 0)
LastOutsideTokenChange->TokenLength += LastOutsideTokenChange->TokenLength += P.TokenLength + P.Spaces;
Changes[i - 1].TokenLength + Changes[i - 1].Spaces; else
} else { LastOutsideTokenChange = &P;
LastOutsideTokenChange = &Changes[i - 1];
}
Changes[i].PreviousEndOfTokenColumn = C.PreviousEndOfTokenColumn = P.StartOfTokenColumn + P.TokenLength;
Changes[i - 1].StartOfTokenColumn + Changes[i - 1].TokenLength;
Changes[i - 1].IsTrailingComment = P.IsTrailingComment =
(Changes[i].NewlinesBefore > 0 || Changes[i].Tok->is(tok::eof) || (C.NewlinesBefore > 0 || C.Tok->is(tok::eof) ||
(Changes[i].IsInsideToken && Changes[i].Tok->is(tok::comment))) && (C.IsInsideToken && C.Tok->is(tok::comment))) &&
Changes[i - 1].Tok->is(tok::comment) && P.Tok->is(tok::comment) &&
// FIXME: This is a dirty hack. The problem is that // FIXME: This is a dirty hack. The problem is that
// BreakableLineCommentSection does comment reflow changes and here is // BreakableLineCommentSection does comment reflow changes and here is
// the aligning of trailing comments. Consider the case where we reflow // the aligning of trailing comments. Consider the case where we reflow