[llvm-commits] [llvm] r77160 - /llvm/trunk/include/llvm/ADT/StringRef.h

Chris Lattner sabre at nondot.org
Sun Jul 26 10:46:26 PDT 2009


Author: lattner
Date: Sun Jul 26 12:46:03 2009
New Revision: 77160

URL: http://llvm.org/viewvc/llvm-project?rev=77160&view=rev
Log:
Use the RHS length instead of the LHS length.  They are both the same,
but this ends up compiling code like this:

int foo(const StringRef &R) {
  return R == "food";
}

to use a constant sized memcmp instead of a variable memcmp.


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=77160&r1=77159&r2=77160&view=diff

==============================================================================
--- llvm/trunk/include/llvm/ADT/StringRef.h (original)
+++ llvm/trunk/include/llvm/ADT/StringRef.h Sun Jul 26 12:46:03 2009
@@ -81,7 +81,7 @@
     /// 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);
+              memcmp(Data, RHS.Data, RHS.Length) == 0);
     }
 
     /// compare - Compare two strings; the result is -1, 0, or 1 if this string





More information about the llvm-commits mailing list