[clang][Diagnostics][NFC] Move Buf{Start,End} out of the loop
authorTimm Bäder <tbaeder@redhat.com>
Wed, 24 May 2023 06:16:04 +0000 (08:16 +0200)
committerTimm Bäder <tbaeder@redhat.com>
Wed, 31 May 2023 08:21:24 +0000 (10:21 +0200)
They don't change inside the loop.

clang/lib/Frontend/TextDiagnostic.cpp

index f817ab7..11ae266 100644 (file)
@@ -1134,6 +1134,8 @@ void TextDiagnostic::emitSnippetAndCaret(
   StringRef BufData = Loc.getBufferData(&Invalid);
   if (Invalid)
     return;
+  const char *BufStart = BufData.data();
+  const char *BufEnd = BufStart + BufData.size();
 
   unsigned CaretLineNo = Loc.getLineNumber();
   unsigned CaretColNo = Loc.getColumnNumber();
@@ -1167,9 +1169,6 @@ void TextDiagnostic::emitSnippetAndCaret(
 
   for (unsigned LineNo = Lines.first; LineNo != Lines.second + 1;
        ++LineNo, ++DisplayLineNo) {
-    const char *BufStart = BufData.data();
-    const char *BufEnd = BufStart + BufData.size();
-
     // Rewind from the current position to the start of the line.
     const char *LineStart =
         BufStart +