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

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 12 02:31:32 PDT 2026


================
@@ -110,19 +113,37 @@ static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) {
     OS << L << '\n';
   };
 
-  const char *B = Contents.begin();
-  const char *P = nullptr, *E = nullptr, *S = nullptr;
-  for (P = Contents.begin(), E = Contents.end(); P < E; ++P) {
-    if (isPrint(*P) || *P == '\t') {
-      if (S == nullptr)
-        S = P;
-    } else if (S) {
-      print(S - B, StringRef(S, P - S));
-      S = nullptr;
+  Buffer.resize_for_overwrite(sys::fs::DefaultReadChunkSize);
+  std::string StringBuffer;
+  unsigned Offset = 0;
+  while (true) {
+    Expected<size_t> ReadBytesOrErr = sys::fs::readNativeFile(
----------------
jh7370 wrote:

It would be worth a comment saying why we are reading in chunks and not reading the whole file.

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


More information about the llvm-commits mailing list