[PATCH] D17499: [ELF] - replaced std::function with raw pointers in LinkerScript.cpp

George Rimar via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 22 02:08:10 PST 2016


grimar created this revision.
grimar added reviewers: dblaikie, ruiu, rafael.
grimar added subscribers: llvm-commits, grimar.

Little change as was proposed by David Blaikie.

Rui, Rafal, what do you think ?


http://reviews.llvm.org/D17499

Files:
  ELF/LinkerScript.cpp

Index: ELF/LinkerScript.cpp
===================================================================
--- ELF/LinkerScript.cpp
+++ ELF/LinkerScript.cpp
@@ -83,21 +83,11 @@
 }
 
 class elf2::ScriptParser {
+  typedef void (ScriptParser::*CmdHandler)();
+
 public:
   ScriptParser(BumpPtrAllocator *A, StringRef S, bool B)
-      : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {
-    Cmd["ENTRY"] = std::mem_fn(&ScriptParser::readEntry);
-    Cmd["EXTERN"] = std::mem_fn(&ScriptParser::readExtern);
-    Cmd["GROUP"] = std::mem_fn(&ScriptParser::readGroup);
-    Cmd["INCLUDE"] = std::mem_fn(&ScriptParser::readInclude);
-    Cmd["INPUT"] = std::mem_fn(&ScriptParser::readGroup);
-    Cmd["OUTPUT"] = std::mem_fn(&ScriptParser::readOutput);
-    Cmd["OUTPUT_ARCH"] = std::mem_fn(&ScriptParser::readOutputArch);
-    Cmd["OUTPUT_FORMAT"] = std::mem_fn(&ScriptParser::readOutputFormat);
-    Cmd["SEARCH_DIR"] = std::mem_fn(&ScriptParser::readSearchDir);
-    Cmd["SECTIONS"] = std::mem_fn(&ScriptParser::readSections);
-    Cmd[";"] = [](ScriptParser &) {};
-  }
+      : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}
 
   void run();
 
@@ -127,7 +117,18 @@
 
   StringSaver Saver;
   std::vector<StringRef> Tokens;
-  llvm::StringMap<std::function<void(ScriptParser &)>> Cmd;
+  llvm::StringMap<CmdHandler> Cmd{
+      {"ENTRY", &ScriptParser::readEntry},
+      {"EXTERN", &ScriptParser::readExtern},
+      {"GROUP", &ScriptParser::readGroup},
+      {"INCLUDE", &ScriptParser::readInclude},
+      {"INPUT", &ScriptParser::readGroup},
+      {"OUTPUT", &ScriptParser::readOutput},
+      {"OUTPUT_ARCH", &ScriptParser::readOutputArch},
+      {"OUTPUT_FORMAT", &ScriptParser::readOutputFormat},
+      {"SEARCH_DIR", &ScriptParser::readSearchDir},
+      {"SECTIONS", &ScriptParser::readSections},
+      {";", nullptr}};
   size_t Pos = 0;
   bool IsUnderSysroot;
   bool Error = false;
@@ -138,8 +139,9 @@
     StringRef Tok = next();
     auto It = Cmd.find(Tok);
     if (It != Cmd.end()) {
-      std::function<void(ScriptParser &)> &Handler = It->second;
-      Handler(*this);
+      CmdHandler Handler = It->second;
+      if (Handler)
+        (this->*Handler)();
     } else {
       setError("unknown directive: " + Tok);
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17499.48659.patch
Type: text/x-patch
Size: 2247 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160222/57556b40/attachment.bin>


More information about the llvm-commits mailing list