[llvm] r357457 - [Internalize] Replace fstream with line_iterator for -internalize-public-api-file

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 2 02:11:18 PDT 2019


Author: maskray
Date: Tue Apr  2 02:11:18 2019
New Revision: 357457

URL: http://llvm.org/viewvc/llvm-project?rev=357457&view=rev
Log:
[Internalize] Replace fstream with line_iterator for -internalize-public-api-file

This makes my libLLVMipo.so.9svn smaller by 360 bytes.

Modified:
    llvm/trunk/lib/Transforms/IPO/Internalize.cpp

Modified: llvm/trunk/lib/Transforms/IPO/Internalize.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/IPO/Internalize.cpp?rev=357457&r1=357456&r2=357457&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/IPO/Internalize.cpp (original)
+++ llvm/trunk/lib/Transforms/IPO/Internalize.cpp Tue Apr  2 02:11:18 2019
@@ -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 <fstream>
 #include <set>
 using namespace llvm;
 
@@ -72,18 +73,15 @@ private:
 
   void LoadFile(StringRef Filename) {
     // Load the APIFile...
-    std::ifstream In(Filename.data());
-    if (!In.good()) {
+    ErrorOr<std::unique_ptr<MemoryBuffer>> 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




More information about the llvm-commits mailing list