[llvm] 1e67d77 - Partially revert 931d04be2fc8

Benjamin Kramer via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 16 01:40:20 PST 2023


Author: Benjamin Kramer
Date: 2023-01-16T10:40:10+01:00
New Revision: 1e67d775da7cc20e00f42bbb533a037f7c00087c

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

LOG: Partially revert 931d04be2fc8

This change makes StringRefTest fail in some configuration. Might be a
standard library issue or miscompile.

Added: 
    

Modified: 
    llvm/include/llvm/ADT/StringRef.h

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ADT/StringRef.h b/llvm/include/llvm/ADT/StringRef.h
index 8ebd5fc346e60..2d2f0bedfe1f8 100644
--- a/llvm/include/llvm/ADT/StringRef.h
+++ b/llvm/include/llvm/ADT/StringRef.h
@@ -175,7 +175,14 @@ namespace llvm {
     /// if this string is lexicographically less than, equal to, or greater than
     /// the \p RHS.
     [[nodiscard]] int compare(StringRef RHS) const {
-      return std::string_view(*this).compare(RHS);
+      // Check the prefix for a mismatch.
+      if (int Res = compareMemory(Data, RHS.Data, std::min(Length, RHS.Length)))
+        return Res < 0 ? -1 : 1;
+
+      // Otherwise the prefixes match, so we only need to check the lengths.
+      if (Length == RHS.Length)
+        return 0;
+      return Length < RHS.Length ? -1 : 1;
     }
 
     /// Compare two strings, ignoring case.


        


More information about the llvm-commits mailing list