[llvm] bea5a95 - [gold] Simplify with StringRef::consume_front. NFC

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 24 12:39:44 PDT 2020


Author: Fangrui Song
Date: 2020-04-24T12:39:35-07:00
New Revision: bea5a958d317652fe68d66f848d096449063234c

URL: https://github.com/llvm/llvm-project/commit/bea5a958d317652fe68d66f848d096449063234c
DIFF: https://github.com/llvm/llvm-project/commit/bea5a958d317652fe68d66f848d096449063234c.diff

LOG: [gold] Simplify with StringRef::consume_front. NFC

Reviewed By: tejohnson

Differential Revision: https://reviews.llvm.org/D78819

Added: 
    

Modified: 
    llvm/tools/gold/gold-plugin.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/tools/gold/gold-plugin.cpp b/llvm/tools/gold/gold-plugin.cpp
index 6d2369f52c42..0b249d222063 100644
--- a/llvm/tools/gold/gold-plugin.cpp
+++ b/llvm/tools/gold/gold-plugin.cpp
@@ -224,15 +224,14 @@ namespace options {
       return;
     llvm::StringRef opt = opt_;
 
-    if (opt.startswith("mcpu=")) {
-      mcpu = std::string(opt.substr(strlen("mcpu=")));
-    } else if (opt.startswith("extra-library-path=")) {
-      extra_library_path =
-          std::string(opt.substr(strlen("extra_library_path=")));
-    } else if (opt.startswith("mtriple=")) {
-      triple = std::string(opt.substr(strlen("mtriple=")));
-    } else if (opt.startswith("obj-path=")) {
-      obj_path = std::string(opt.substr(strlen("obj-path=")));
+    if (opt.consume_front("mcpu=")) {
+      mcpu = std::string(opt);
+    } else if (opt.consume_front("extra-library-path=")) {
+      extra_library_path = std::string(opt);
+    } else if (opt.consume_front("mtriple=")) {
+      triple = std::string(opt);
+    } else if (opt.consume_front("obj-path=")) {
+      obj_path = std::string(opt);
     } else if (opt == "emit-llvm") {
       TheOutputType = OT_BC_ONLY;
     } else if (opt == "save-temps") {
@@ -245,67 +244,62 @@ namespace options {
       thinlto = true;
     } else if (opt == "thinlto-index-only") {
       thinlto_index_only = true;
-    } else if (opt.startswith("thinlto-index-only=")) {
+    } else if (opt.consume_front("thinlto-index-only=")) {
       thinlto_index_only = true;
-      thinlto_linked_objects_file =
-          std::string(opt.substr(strlen("thinlto-index-only=")));
+      thinlto_linked_objects_file = std::string(opt);
     } else if (opt == "thinlto-emit-imports-files") {
       thinlto_emit_imports_files = true;
-    } else if (opt.startswith("thinlto-prefix-replace=")) {
-      thinlto_prefix_replace =
-          std::string(opt.substr(strlen("thinlto-prefix-replace=")));
+    } else if (opt.consume_front("thinlto-prefix-replace=")) {
+      thinlto_prefix_replace = std::string(opt);
       if (thinlto_prefix_replace.find(';') == std::string::npos)
         message(LDPL_FATAL, "thinlto-prefix-replace expects 'old;new' format");
-    } else if (opt.startswith("thinlto-object-suffix-replace=")) {
-      thinlto_object_suffix_replace =
-          std::string(opt.substr(strlen("thinlto-object-suffix-replace=")));
+    } else if (opt.consume_front("thinlto-object-suffix-replace=")) {
+      thinlto_object_suffix_replace = std::string(opt);
       if (thinlto_object_suffix_replace.find(';') == std::string::npos)
         message(LDPL_FATAL,
                 "thinlto-object-suffix-replace expects 'old;new' format");
-    } else if (opt.startswith("cache-dir=")) {
-      cache_dir = std::string(opt.substr(strlen("cache-dir=")));
-    } else if (opt.startswith("cache-policy=")) {
-      cache_policy = std::string(opt.substr(strlen("cache-policy=")));
+    } else if (opt.consume_front("cache-dir=")) {
+      cache_dir = std::string(opt);
+    } else if (opt.consume_front("cache-policy=")) {
+      cache_policy = std::string(opt);
     } else if (opt.size() == 2 && opt[0] == 'O') {
       if (opt[1] < '0' || opt[1] > '3')
         message(LDPL_FATAL, "Optimization level must be between 0 and 3");
       OptLevel = opt[1] - '0';
-    } else if (opt.startswith("jobs=")) {
-      StringRef Num(opt_ + 5);
-      if (!get_threadpool_strategy(Num))
-        message(LDPL_FATAL, "Invalid parallelism level: %s", Num.data());
-      Parallelism = Num.str();
-    } else if (opt.startswith("lto-partitions=")) {
-      if (opt.substr(strlen("lto-partitions="))
-              .getAsInteger(10, ParallelCodeGenParallelismLevel))
+    } else if (opt.consume_front("jobs=")) {
+      Parallelism = std::string(opt);
+      if (!get_threadpool_strategy(opt))
+        message(LDPL_FATAL, "Invalid parallelism level: %s",
+                Parallelism.c_str());
+    } else if (opt.consume_front("lto-partitions=")) {
+      if (opt.getAsInteger(10, ParallelCodeGenParallelismLevel))
         message(LDPL_FATAL, "Invalid codegen partition level: %s", opt_ + 5);
     } else if (opt == "disable-verify") {
       DisableVerify = true;
-    } else if (opt.startswith("sample-profile=")) {
-      sample_profile = std::string(opt.substr(strlen("sample-profile=")));
+    } else if (opt.consume_front("sample-profile=")) {
+      sample_profile = std::string(opt);
     } else if (opt == "cs-profile-generate") {
       cs_pgo_gen = true;
-    } else if (opt.startswith("cs-profile-path=")) {
-      cs_profile_path = std::string(opt.substr(strlen("cs-profile-path=")));
+    } else if (opt.consume_front("cs-profile-path=")) {
+      cs_profile_path = std::string(opt);
     } else if (opt == "new-pass-manager") {
       new_pass_manager = true;
     } else if (opt == "debug-pass-manager") {
       debug_pass_manager = true;
     } else if (opt == "whole-program-visibility") {
       whole_program_visibility = true;
-    } else if (opt.startswith("dwo_dir=")) {
-      dwo_dir = std::string(opt.substr(strlen("dwo_dir=")));
-    } else if (opt.startswith("opt-remarks-filename=")) {
-      RemarksFilename =
-          std::string(opt.substr(strlen("opt-remarks-filename=")));
-    } else if (opt.startswith("opt-remarks-passes=")) {
-      RemarksPasses = std::string(opt.substr(strlen("opt-remarks-passes=")));
+    } else if (opt.consume_front("dwo_dir=")) {
+      dwo_dir = std::string(opt);
+    } else if (opt.consume_front("opt-remarks-filename=")) {
+      RemarksFilename = std::string(opt);
+    } else if (opt.consume_front("opt-remarks-passes=")) {
+      RemarksPasses = std::string(opt);
     } else if (opt == "opt-remarks-with-hotness") {
       RemarksWithHotness = true;
-    } else if (opt.startswith("opt-remarks-format=")) {
-      RemarksFormat = std::string(opt.substr(strlen("opt-remarks-format=")));
-    } else if (opt.startswith("stats-file=")) {
-      stats_file = std::string(opt.substr(strlen("stats-file=")));
+    } else if (opt.consume_front("opt-remarks-format=")) {
+      RemarksFormat = std::string(opt);
+    } else if (opt.consume_front("stats-file=")) {
+      stats_file = std::string(opt);
     } else {
       // Save this option to pass to the code generator.
       // ParseCommandLineOptions() expects argv[0] to be program name. Lazily


        


More information about the llvm-commits mailing list