]> granicus.if.org Git - icu/commitdiff
ICU-9297 use memcmp() in UnicodeString::operator==()
authorMarkus Scherer <markus.icu@gmail.com>
Mon, 8 Oct 2012 18:24:41 +0000 (18:24 +0000)
committerMarkus Scherer <markus.icu@gmail.com>
Mon, 8 Oct 2012 18:24:41 +0000 (18:24 +0000)
X-SVN-Rev: 32552

icu4c/source/common/unicode/unistr.h
icu4c/source/common/unistr.cpp

index 6c5d1f4edc937a8d0a9534df5cbbc03fb30d7045..4ebeb516824d2be9f89f0df757cf6331adc02fdb 100644 (file)
@@ -3272,6 +3272,11 @@ private:
   toUTF8(int32_t start, int32_t len,
          char *target, int32_t capacity) const;
 
+  /**
+   * Internal string contents comparison, called by operator==.
+   * Requires: this & text not bogus and have same lengths.
+   */
+  UBool doEquals(const UnicodeString &text, int32_t len) const;
 
   inline int8_t
   doCompare(int32_t start,
@@ -3665,10 +3670,7 @@ UnicodeString::operator== (const UnicodeString& text) const
     return text.isBogus();
   } else {
     int32_t len = length(), textLength = text.length();
-    return
-      !text.isBogus() &&
-      len == textLength &&
-      doCompare(0, len, text, 0, textLength) == 0;
+    return !text.isBogus() && len == textLength && doEquals(text, len);
   }
 }
 
index 3c1292d39df61e1d8c246fbd46706a76aa3fec24..5db94d3baf52aea1ade7ead65b0254df160280fe 100644 (file)
@@ -570,6 +570,13 @@ UChar32 UnicodeString::unescapeAt(int32_t &offset) const {
 //========================================
 // Read-only implementation
 //========================================
+UBool
+UnicodeString::doEquals(const UnicodeString &text, int32_t len) const {
+  // Requires: this & text not bogus and have same lengths.
+  // Byte-wise comparison works for equality regardless of endianness.
+  return uprv_memcmp(getArrayStart(), text.getArrayStart(), len * U_SIZEOF_UCHAR) == 0;
+}
+
 int8_t
 UnicodeString::doCompare( int32_t start,
               int32_t length,