ICU-9297 use memcmp() in UnicodeString::operator==()

X-SVN-Rev: 32552
This commit is contained in:
Markus Scherer 2012-10-08 18:24:41 +00:00
parent 7c176da599
commit 33eb771977
2 changed files with 13 additions and 4 deletions

View 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);
}
}

View 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,