[llvm] [SourceMgr] Clean up handling of line ending characters (PR #120605)
Jay Foad via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 7 04:09:58 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
----------------
jayfoad wrote:
Which parts of the existing code do you like?
I don't care too much which line endings we handle. The important part of this change is to store offsets to the start of each line (including the first line and the last-plus-one line) instead of the terminating LF characters, to enable the other simplifications in this file.
https://github.com/llvm/llvm-project/pull/120605
More information about the llvm-commits
mailing list