[cfe-commits] r139225 - /cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Chandler Carruth chandlerc at gmail.com
Tue Sep 6 22:01:10 PDT 2011


Author: chandlerc
Date: Wed Sep  7 00:01:10 2011
New Revision: 139225

URL: http://llvm.org/viewvc/llvm-project?rev=139225&view=rev
Log:
Don't compute the same line number in two places, once inside a loop.

Modified:
    cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp

Modified: cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp?rev=139225&r1=139224&r2=139225&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp (original)
+++ cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp Wed Sep  7 00:01:10 2011
@@ -505,6 +505,7 @@
     if (Invalid)
       return;
 
+    unsigned LineNo = SM.getLineNumber(FID, FileOffset);
     unsigned ColNo = SM.getColumnNumber(FID, FileOffset);
     unsigned CaretEndColNo
       = ColNo + Lexer::MeasureTokenLength(Loc, SM, LangOpts);
@@ -533,14 +534,10 @@
     std::string CaretLine(LineEnd-LineStart, ' ');
 
     // Highlight all of the characters covered by Ranges with ~ characters.
-    if (!Ranges.empty()) {
-      unsigned LineNo = SM.getLineNumber(FID, FileOffset);
-
-      for (SmallVectorImpl<CharSourceRange>::iterator I = Ranges.begin(),
-                                                      E = Ranges.end();
-           I != E; ++I)
-        Printer.HighlightRange(*I, SM, LineNo, FID, CaretLine, SourceLine);
-    }
+    for (SmallVectorImpl<CharSourceRange>::iterator I = Ranges.begin(),
+                                                    E = Ranges.end();
+         I != E; ++I)
+      Printer.HighlightRange(*I, SM, LineNo, FID, CaretLine, SourceLine);
 
     // Next, insert the caret itself.
     if (ColNo-1 < CaretLine.size())
@@ -579,7 +576,7 @@
       CaretLine = ' ' + CaretLine;
     }
 
-    std::string FixItInsertionLine = BuildFixItInsertionLine(FID, FileOffset,
+    std::string FixItInsertionLine = BuildFixItInsertionLine(LineNo,
                                                              LineStart, LineEnd,
                                                              Hints);
 
@@ -618,7 +615,7 @@
   }
 
 private:
-  std::string BuildFixItInsertionLine(FileID FID, unsigned FileOffset,
+  std::string BuildFixItInsertionLine(unsigned LineNo,
                                       const char *LineStart,
                                       const char *LineEnd,
                                       ArrayRef<FixItHint> Hints) {
@@ -633,8 +630,7 @@
         // code is on the same line as the caret.
         std::pair<FileID, unsigned> HintLocInfo
           = SM.getDecomposedExpansionLoc(I->RemoveRange.getBegin());
-        if (SM.getLineNumber(HintLocInfo.first, HintLocInfo.second) ==
-              SM.getLineNumber(FID, FileOffset)) {
+        if (LineNo == SM.getLineNumber(HintLocInfo.first, HintLocInfo.second)) {
           // Insert the new code into the line just below the code
           // that the user wrote.
           unsigned HintColNo





More information about the cfe-commits mailing list