From: Fangrui Song Date: Tue, 2 Apr 2019 09:11:18 +0000 (+0000) Subject: [Internalize] Replace fstream with line_iterator for -internalize-public-api-file X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5377f1995b0d462123700541a6b4d06ccdf1b1c4;p=llvm [Internalize] Replace fstream with line_iterator for -internalize-public-api-file This makes my libLLVMipo.so.9svn smaller by 360 bytes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@357457 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/IPO/Internalize.cpp b/lib/Transforms/IPO/Internalize.cpp index 008817c3c59..8423a8a4d71 100644 --- a/lib/Transforms/IPO/Internalize.cpp +++ b/lib/Transforms/IPO/Internalize.cpp @@ -27,10 +27,11 @@ #include "llvm/Pass.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Debug.h" +#include "llvm/Support/LineIterator.h" +#include "llvm/Support/MemoryBuffer.h" #include "llvm/Support/raw_ostream.h" #include "llvm/Transforms/IPO.h" #include "llvm/Transforms/Utils/GlobalStatus.h" -#include #include using namespace llvm; @@ -72,18 +73,15 @@ private: void LoadFile(StringRef Filename) { // Load the APIFile... - std::ifstream In(Filename.data()); - if (!In.good()) { + ErrorOr> Buf = + MemoryBuffer::getFile(Filename); + if (!Buf) { errs() << "WARNING: Internalize couldn't load file '" << Filename << "'! Continuing as if it's empty.\n"; return; // Just continue as if the file were empty } - while (In) { - std::string Symbol; - In >> Symbol; - if (!Symbol.empty()) - ExternalNames.insert(Symbol); - } + for (line_iterator I(*Buf->get(), true), E; I != E; ++I) + ExternalNames.insert(*I); } }; } // end anonymous namespace