[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


================
@@ -174,13 +195,17 @@ int main(int argc, char **argv) {
     InputFileNames.push_back("-");
 
   for (const auto &File : InputFileNames) {
-    ErrorOr<std::unique_ptr<MemoryBuffer>> Buffer =
-        MemoryBuffer::getFileOrSTDIN(File, /*IsText=*/true);
-    if (std::error_code EC = Buffer.getError())
-      errs() << File << ": " << EC.message() << '\n';
-    else
-      strings(llvm::outs(), File == "-" ? "{standard input}" : File,
-              Buffer.get()->getMemBufferRef().getBuffer());
+    if (File == "-") {
+      strings(llvm::outs(), "{standard input}", sys::fs::getStdinHandle());
+    } else {
+      Expected<sys::fs::file_t> FDOrErr = sys::fs::openNativeFileForReadWrite(
----------------
jh7370 wrote:

`openNativeFileForRead` would be better since you don't need to write to the file.

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


More information about the llvm-commits mailing list