[llvm] [SourceMgr] Clean up handling of line ending characters (PR #120605)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 6 21:56:49 PST 2025


================
@@ -91,19 +91,32 @@ static std::vector<T> &GetOrCreateOffsetCache(void *&OffsetCache,
   size_t Sz = Buffer->getBufferSize();
   assert(Sz <= std::numeric_limits<T>::max());
   StringRef S = Buffer->getBuffer();
-  for (size_t N = 0; N < Sz; ++N) {
-    if (S[N] == '\n')
-      Offsets->push_back(static_cast<T>(N));
+
+  // The cache always includes 0 (for the start of the first line) and Sz (so
----------------
MaskRay wrote:

I like the existing code. You can ignore support for classic Mac (CR). There are other places we don't support CR ending. No need to support it.

https://github.com/llvm/llvm-project/pull/120605


More information about the llvm-commits mailing list