[PATCH] D151300: [clang][Diagnostics][NFC] Remove unnecessary StringRef

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 24 00:04:10 PDT 2023


tbaeder updated this revision to Diff 525031.

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151300/new/

https://reviews.llvm.org/D151300

Files:
  clang/lib/Frontend/TextDiagnostic.cpp


Index: clang/lib/Frontend/TextDiagnostic.cpp
===================================================================
--- clang/lib/Frontend/TextDiagnostic.cpp
+++ clang/lib/Frontend/TextDiagnostic.cpp
@@ -1203,14 +1203,12 @@
     if (size_t(LineEnd - LineStart) > MaxLineLengthToPrint)
       return;
 
-    // Trim trailing null-bytes.
-    StringRef Line(LineStart, LineEnd - LineStart);
-    while (!Line.empty() && Line.back() == '\0' &&
-           (LineNo != CaretLineNo || Line.size() > CaretColNo))
-      Line = Line.drop_back();
-
     // Copy the line of code into an std::string for ease of manipulation.
-    std::string SourceLine(Line.begin(), Line.end());
+    std::string SourceLine(LineStart, LineEnd);
+    // Remove trailing null bytes.
+    while (!SourceLine.empty() && SourceLine.back() == '\0' &&
+           (LineNo != CaretLineNo || SourceLine.size() > CaretColNo))
+      SourceLine.pop_back();
 
     // Build the byte to column map.
     const SourceColumnMap sourceColMap(SourceLine, DiagOpts->TabStop);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D151300.525031.patch
Type: text/x-patch
Size: 1030 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230524/db391110/attachment.bin>


More information about the cfe-commits mailing list