Remove memory allocation with string
authorAditya Kumar <1894981+hiraditya@users.noreply.github.com>
Sat, 5 Dec 2020 19:43:45 +0000 (11:43 -0800)
committerAditya Kumar <1894981+hiraditya@users.noreply.github.com>
Sat, 5 Dec 2020 23:14:44 +0000 (15:14 -0800)
Differential Revision: https://reviews.llvm.org/D92506

llvm/lib/Option/OptTable.cpp

index 304c09f..9564b44 100644 (file)
@@ -196,11 +196,13 @@ static unsigned matchOption(const OptTable::Info *I, StringRef Str,
 
 // Returns true if one of the Prefixes + In.Names matches Option
 static bool optionMatches(const OptTable::Info &In, StringRef Option) {
-  if (In.Prefixes)
+  if (In.Prefixes) {
+    StringRef InName(In.Name);
     for (size_t I = 0; In.Prefixes[I]; I++)
-      if (Option.endswith(In.Name))
-        if (Option == std::string(In.Prefixes[I]) + In.Name)
+      if (Option.endswith(InName))
+        if (Option.slice(0, Option.size() - InName.size()) == In.Prefixes[I])
           return true;
+  }
   return false;
 }