[PATCH] D60117: [BPF] Replace fstream and sstream with line_iterator

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 02:40:33 PDT 2019


MaskRay created this revision.
MaskRay added a reviewer: yonghong-song.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This makes libLLVMBPFCodeGen.so 1128 bytes smaller for my build.


Repository:
  rL LLVM

https://reviews.llvm.org/D60117

Files:
  lib/Target/BPF/BTFDebug.cpp


Index: lib/Target/BPF/BTFDebug.cpp
===================================================================
--- lib/Target/BPF/BTFDebug.cpp
+++ lib/Target/BPF/BTFDebug.cpp
@@ -18,8 +18,7 @@
 #include "llvm/MC/MCObjectFileInfo.h"
 #include "llvm/MC/MCSectionELF.h"
 #include "llvm/MC/MCStreamer.h"
-#include <fstream>
-#include <sstream>
+#include "llvm/Support/LineIterator.h"
 
 using namespace llvm;
 
@@ -559,16 +558,16 @@
   std::string Line;
   Content.push_back(Line); // Line 0 for empty string
 
+  std::unique_ptr<MemoryBuffer> Buf;
   auto Source = File->getSource();
-  if (Source) {
-    std::istringstream InputString(Source.getValue());
-    while (std::getline(InputString, Line))
-      Content.push_back(Line);
-  } else {
-    std::ifstream InputFile(FileName);
-    while (std::getline(InputFile, Line))
-      Content.push_back(Line);
-  }
+  if (Source)
+    Buf = MemoryBuffer::getMemBufferCopy(*Source);
+  else if (ErrorOr<std::unique_ptr<MemoryBuffer>> BufOrErr =
+               MemoryBuffer::getFile(FileName))
+    Buf = std::move(*BufOrErr);
+  if (Buf)
+    for (line_iterator I(*Buf, false), E; I != E; ++I)
+      Content.push_back(*I);
 
   FileContent[FileName] = Content;
   return FileName;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60117.193247.patch
Type: text/x-patch
Size: 1222 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190402/9799b48c/attachment.bin>


More information about the llvm-commits mailing list