[llvm] r357489 - [BPF] Replace fstream and sstream with line_iterator
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 2 09:15:46 PDT 2019
Author: maskray
Date: Tue Apr 2 09:15:46 2019
New Revision: 357489
URL: http://llvm.org/viewvc/llvm-project?rev=357489&view=rev
Log:
[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
Modified:
llvm/trunk/lib/Target/BPF/BTFDebug.cpp
Modified: llvm/trunk/lib/Target/BPF/BTFDebug.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/BPF/BTFDebug.cpp?rev=357489&r1=357488&r2=357489&view=diff
==============================================================================
--- llvm/trunk/lib/Target/BPF/BTFDebug.cpp (original)
+++ llvm/trunk/lib/Target/BPF/BTFDebug.cpp Tue Apr 2 09:15:46 2019
@@ -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::populateFileConten
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;
More information about the llvm-commits
mailing list