[llvm] r256050 - Use a lambda to reduce code duplication.

Rafael Espindola via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 18 14:40:28 PST 2015


Author: rafael
Date: Fri Dec 18 16:40:27 2015
New Revision: 256050

URL: http://llvm.org/viewvc/llvm-project?rev=256050&view=rev
Log:
Use a lambda to reduce code duplication.

Modified:
    llvm/trunk/tools/llvm-extract/llvm-extract.cpp

Modified: llvm/trunk/tools/llvm-extract/llvm-extract.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-extract/llvm-extract.cpp?rev=256050&r1=256049&r2=256050&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-extract/llvm-extract.cpp (original)
+++ llvm/trunk/tools/llvm-extract/llvm-extract.cpp Fri Dec 18 16:40:27 2015
@@ -222,35 +222,27 @@ int main(int argc, char **argv) {
     }
   }
 
-  // Materialize requisite global values.
-  if (!DeleteFn)
-    for (size_t i = 0, e = GVs.size(); i != e; ++i) {
-      GlobalValue *GV = GVs[i];
-      if (std::error_code EC = GV->materialize()) {
-        errs() << argv[0] << ": error reading input: " << EC.message() << "\n";
-        return 1;
-      }
+  auto Materialize = [&](GlobalValue &GV) {
+    if (std::error_code EC = GV.materialize()) {
+      errs() << argv[0] << ": error reading input: " << EC.message() << "\n";
+      exit(1);
     }
-  else {
+  };
+
+  // Materialize requisite global values.
+  if (!DeleteFn) {
+    for (size_t i = 0, e = GVs.size(); i != e; ++i)
+      Materialize(*GVs[i]);
+  } else {
     // Deleting. Materialize every GV that's *not* in GVs.
     SmallPtrSet<GlobalValue *, 8> GVSet(GVs.begin(), GVs.end());
     for (auto &G : M->globals()) {
-      if (!GVSet.count(&G)) {
-        if (std::error_code EC = G.materialize()) {
-          errs() << argv[0] << ": error reading input: " << EC.message()
-                 << "\n";
-          return 1;
-        }
-      }
+      if (!GVSet.count(&G))
+        Materialize(G);
     }
     for (auto &F : *M) {
-      if (!GVSet.count(&F)) {
-        if (std::error_code EC = F.materialize()) {
-          errs() << argv[0] << ": error reading input: " << EC.message()
-                 << "\n";
-          return 1;
-        }
-      }
+      if (!GVSet.count(&F))
+        Materialize(F);
     }
   }
 




More information about the llvm-commits mailing list