From: Fangrui Song Date: Tue, 2 Apr 2019 16:15:46 +0000 (+0000) Subject: [BPF] Replace fstream and sstream with line_iterator X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=948cc167892b92a56573ef35818d8b946c6b40ba;p=llvm [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 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357489 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/BPF/BTFDebug.cpp b/lib/Target/BPF/BTFDebug.cpp index 6218ef41add..1fa5faf9d83 100644 --- a/lib/Target/BPF/BTFDebug.cpp +++ b/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 -#include +#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 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> 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;