[llvm] [llvm-strings] Use small buffer instead of reading whole file (PR #163073)

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 4 01:47:14 PDT 2026


================
@@ -150,66 +150,89 @@ static void strings(raw_ostream &OS, StringRef FileName,
     const char *Cur = Begin;
 
     // Handle the remaining part from the previous chunk.
-    // The previous chunk can be either no longer than MinSize or part of the
+    // The previous chunk can be either shorter than MinSize or part of the
     // string.
     // Keep the buffer size bounded. With a small Min, a long string spanning
     // multiple chunks will have at most DefaultReadChunkSize bytes, since the
     // buffer is printed immediately with the header (guarded by the second if).
     // With a large Min, the buffer must hold at least Min bytes, since we need
     // enough data to decide whether to print it.
     if (InString || !Candidate.empty()) {
+      // Find the end of the current buffer
       while (Cur != End && isStringChar(*Cur))
         ++Cur;
       size_t Len = Cur - Begin;
       if (InString) {
+        // Print the remaining part if the previous chunk has already printed
+        // the header. E.g. header: aaaaa | bbbbb, where | is the chunk
+        // boundary.                        ^
         OS << StringRef(Begin, Len);
       } else if (Candidate.size() + Len >= Min) {
+        // If the header hasn't been printed yet (e.g. the previous candidate
+        // was smaller than Min), but we can print it now, print the header
+        // first, followed by the candidate from the previous chunk and the
+        // current string. E.g. '\0' | bbbbbb
----------------
jh7370 wrote:

I'd include a non-zero length bit before the chunk boundary, e.g. "aa | bbbbb"

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


More information about the llvm-commits mailing list