[llvm-commits] [llvm] r76588 - /llvm/trunk/include/llvm/ADT/StringRef.h
Daniel Dunbar
daniel at zuster.org
Tue Jul 21 10:25:52 PDT 2009
Author: ddunbar
Date: Tue Jul 21 12:25:46 2009
New Revision: 76588
URL: http://llvm.org/viewvc/llvm-project?rev=76588&view=rev
Log:
Move StringRef comparison operators out of class.
Also, tweak the return type of size().
Modified:
llvm/trunk/include/llvm/ADT/StringRef.h
Modified: llvm/trunk/include/llvm/ADT/StringRef.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringRef.h?rev=76588&r1=76587&r2=76588&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Tue Jul 21 12:25:46 2009
@@ -73,7 +73,14 @@
bool empty() const { return Length == 0; }
/// size - Get the string size.
- unsigned size() const { return Length; }
+ size_t size() const { return Length; }
+
+ /// equals - Check for string equality, this is more efficient than
+ /// compare() in when the relative ordering of inequal strings isn't needed.
+ bool equals(const StringRef &RHS) const {
+ return (Length == RHS.Length &&
+ memcmp(Data, RHS.Data, Length) == 0);
+ }
/// compare - Compare two strings; the result is -1, 0, or 1 if this string
/// is lexicographically less than, equal to, or greater than the \arg RHS.
@@ -95,20 +102,6 @@
/// @name Operator Overloads
/// @{
- bool operator==(const StringRef &RHS) const {
- return Length == RHS.Length && memcmp(Data, RHS.Data, Length) == 0;
- }
-
- bool operator!=(const StringRef &RHS) const { return !(*this == RHS); }
-
- bool operator<(const StringRef &RHS) const { return compare(RHS) == -1; }
-
- bool operator<=(const StringRef &RHS) const { return compare(RHS) != 1; }
-
- bool operator>(const StringRef &RHS) const { return compare(RHS) == 1; }
-
- bool operator>=(const StringRef &RHS) const { return compare(RHS) != -1; }
-
char operator[](size_t Index) const {
assert(Index < Length && "Invalid index!");
return Data[Index];
@@ -142,12 +135,41 @@
/// startswith - Check if this string starts with the given \arg Prefix.
bool startswith(const StringRef &Prefix) const {
- return substr(0, Prefix.Length) == Prefix;
+ return substr(0, Prefix.Length).equals(Prefix);
}
/// @}
};
+ /// @name StringRef Comparison Operators
+ /// @{
+
+ inline bool operator==(const StringRef &LHS, const StringRef &RHS) {
+ return LHS.equals(RHS);
+ }
+
+ inline bool operator!=(const StringRef &LHS, const StringRef &RHS) {
+ return !(LHS == RHS);
+ }
+
+ inline bool operator<(const StringRef &LHS, const StringRef &RHS) {
+ return LHS.compare(RHS) == -1;
+ }
+
+ inline bool operator<=(const StringRef &LHS, const StringRef &RHS) {
+ return LHS.compare(RHS) != 1;
+ }
+
+ inline bool operator>(const StringRef &LHS, const StringRef &RHS) {
+ return LHS.compare(RHS) == 1;
+ }
+
+ inline bool operator>=(const StringRef &LHS, const StringRef &RHS) {
+ return LHS.compare(RHS) != -1;
+ }
+
+ /// @}
+
}
#endif
More information about the llvm-commits
mailing list