[llvm] [LLVM][Option] Refactor option name comparison (PR #108219)

Jan Svoboda via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 12 08:39:32 PDT 2024


================
@@ -30,41 +31,19 @@
 using namespace llvm;
 using namespace llvm::opt;
 
-namespace llvm {
-namespace opt {
-
-// Ordering on Info. The ordering is *almost* case-insensitive lexicographic,
-// with an exception. '\0' comes at the end of the alphabet instead of the
-// beginning (thus options precede any other options which prefix them).
-static int StrCmpOptionNameIgnoreCase(StringRef A, StringRef B) {
-  size_t MinSize = std::min(A.size(), B.size());
-  if (int Res = A.substr(0, MinSize).compare_insensitive(B.substr(0, MinSize)))
-    return Res;
-
-  if (A.size() == B.size())
-    return 0;
-
-  return (A.size() == MinSize) ? 1 /* A is a prefix of B. */
-                               : -1 /* B is a prefix of A */;
-}
-
+namespace llvm::opt {
 #ifndef NDEBUG
-static int StrCmpOptionName(StringRef A, StringRef B) {
-  if (int N = StrCmpOptionNameIgnoreCase(A, B))
-    return N;
-  return A.compare(B);
-}
-
+// Note: This function's logic should match the `IsOptionRecordLess` used in
+// TableGen Option Emitter backend.
----------------
jansvoboda11 wrote:

Would it make sense to extract the prefix-comparing part of this function, use that in `IsOptionRecordLess` and remove this comment?

https://github.com/llvm/llvm-project/pull/108219


More information about the llvm-commits mailing list