summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-04-02 16:15:46 +0000
committerFangrui Song <maskray@google.com>2019-04-02 16:15:46 +0000
commit83db88717bcaade1dc966205ffeb6aadae11ca76 (patch)
tree45511bc2075e0031f3ae233c6e67853e94fa5d0d /llvm/lib
parentc2b831fe1b551b78ec1c392f0a3d15a3351c1b8e (diff)
downloadbcm5719-llvm-83db88717bcaade1dc966205ffeb6aadae11ca76.tar.gz
bcm5719-llvm-83db88717bcaade1dc966205ffeb6aadae11ca76.zip
[BPF] Replace fstream and sstream with line_iterator
Summary: This makes libLLVMBPFCodeGen.so 1128 bytes smaller for my build. Reviewers: yonghong-song Reviewed By: yonghong-song Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D60117 llvm-svn: 357489
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Target/BPF/BTFDebug.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/llvm/lib/Target/BPF/BTFDebug.cpp b/llvm/lib/Target/BPF/BTFDebug.cpp
index 6218ef41add..1fa5faf9d83 100644
--- a/llvm/lib/Target/BPF/BTFDebug.cpp
+++ b/llvm/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 BTFDebug::populateFileContent(const DISubprogram *SP) {
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;
OpenPOWER on IntegriCloud