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

via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 17 03:14:34 PDT 2026


================
@@ -88,41 +90,72 @@ static void parseIntArg(const opt::InputArgList &Args, int ID, T &Value) {
   }
 }
 
-static void strings(raw_ostream &OS, StringRef FileName, StringRef Contents) {
-  auto print = [&OS, FileName](unsigned Offset, StringRef L) {
-    if (L.size() < static_cast<size_t>(MinLength))
-      return;
-    if (PrintFileName)
-      OS << FileName << ": ";
-    switch (Radix) {
-    case none:
-      break;
-    case octal:
-      OS << format("%7o ", Offset);
-      break;
-    case hexadecimal:
-      OS << format("%7x ", Offset);
-      break;
-    case decimal:
-      OS << format("%7u ", Offset);
-      break;
+static void strings(raw_ostream &OS, StringRef FileName,
+                    sys::fs::file_t Handle) {
+  SmallString<sys::fs::DefaultReadChunkSize> Buffer;
+  SmallString<DefaultMinLength> Prefix;
----------------
aokblast wrote:

I noticed that but I thought that is a possible tradeoff. Now, you raised a more plausible answer so I would follow yours. We still create a huge buffer if we have a very large MinLength but I think it is can be controlled.

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


More information about the llvm-commits mailing list