summaryrefslogtreecommitdiffstats
path: root/clang/lib/Basic/SourceManager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Basic/SourceManager.cpp')
-rw-r--r--clang/lib/Basic/SourceManager.cpp21
1 files changed, 8 insertions, 13 deletions
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 5f457d6f9e3..73f2ae96d4a 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -1250,23 +1250,18 @@ static void ComputeLineNumbers(DiagnosticsEngine &Diag, ContentCache *FI,
const unsigned char *Buf = (const unsigned char *)Buffer->getBufferStart();
const unsigned char *End = (const unsigned char *)Buffer->getBufferEnd();
+ const std::size_t BufLen = End - Buf;
unsigned I = 0;
- while (true) {
- // Skip over the contents of the line.
- while (Buf[I] != '\n' && Buf[I] != '\r' && Buf[I] != '\0')
- ++I;
-
- if (Buf[I] == '\n' || Buf[I] == '\r') {
+ while (I < BufLen) {
+ if (Buf[I] == '\n') {
+ LineOffsets.push_back(I + 1);
+ } else if (Buf[I] == '\r') {
// If this is \r\n, skip both characters.
- if (Buf[I] == '\r' && Buf[I+1] == '\n')
+ if (I + 1 < BufLen && Buf[I + 1] == '\n')
++I;
- ++I;
- LineOffsets.push_back(I);
- } else {
- // Otherwise, this is a NUL. If end of file, exit.
- if (Buf+I == End) break;
- ++I;
+ LineOffsets.push_back(I + 1);
}
+ ++I;
}
// Copy the offsets into the FileInfo structure.
OpenPOWER on IntegriCloud