lld/COFF: simplify startswith+substr
authorFangrui Song <i@maskray.me>
Mon, 30 Jan 2023 23:28:10 +0000 (15:28 -0800)
committerFangrui Song <i@maskray.me>
Mon, 30 Jan 2023 23:28:10 +0000 (15:28 -0800)
lld/COFF/Driver.cpp

index a927d41..bd85914 100644 (file)
@@ -1765,20 +1765,17 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) {
         ltoDebugPM = true;
       } else if (s == "noltodebugpassmanager") {
         ltoDebugPM = false;
-      } else if (s.startswith("lldlto=")) {
-        StringRef optLevel = s.substr(7);
-        if (optLevel.getAsInteger(10, config->ltoo) || config->ltoo > 3)
-          error("/opt:lldlto: invalid optimization level: " + optLevel);
-      } else if (s.startswith("lldltojobs=")) {
-        StringRef jobs = s.substr(11);
-        if (!get_threadpool_strategy(jobs))
-          error("/opt:lldltojobs: invalid job count: " + jobs);
-        config->thinLTOJobs = jobs.str();
-      } else if (s.startswith("lldltopartitions=")) {
-        StringRef n = s.substr(17);
-        if (n.getAsInteger(10, config->ltoPartitions) ||
+      } else if (s.consume_front("lldlto=")) {
+        if (s.getAsInteger(10, config->ltoo) || config->ltoo > 3)
+          error("/opt:lldlto: invalid optimization level: " + s);
+      } else if (s.consume_front("lldltojobs=")) {
+        if (!get_threadpool_strategy(s))
+          error("/opt:lldltojobs: invalid job count: " + s);
+        config->thinLTOJobs = s.str();
+      } else if (s.consume_front("lldltopartitions=")) {
+        if (s.getAsInteger(10, config->ltoPartitions) ||
             config->ltoPartitions == 0)
-          error("/opt:lldltopartitions: invalid partition count: " + n);
+          error("/opt:lldltopartitions: invalid partition count: " + s);
       } else if (s != "lbr" && s != "nolbr")
         error("/opt: unknown option: " + s);
     }