diff --git a/intl/locale/src/mac/nsCollationMac.cpp b/intl/locale/src/mac/nsCollationMac.cpp index b35522ccbbdf..dc61b833fb95 100644 --- a/intl/locale/src/mac/nsCollationMac.cpp +++ b/intl/locale/src/mac/nsCollationMac.cpp @@ -60,30 +60,20 @@ nsresult nsCollationMac::GetSortKeyLen(const nsCollationStrength strength, nsresult nsCollationMac::CreateSortKey(const nsCollationStrength strength, const nsString& stringIn, PRUint8* key, PRUint32* outLen) { - // temporary implementation, call FE eventually PRUint32 byteLenIn = stringIn.Length() * sizeof(PRUnichar); + nsAutoString stringNormalized(stringIn); if (byteLenIn > *outLen) { - *outLen = 0; + byteLenIn = 0; } else { - if (mCollation != NULL) { - mCollation->NormalizeString(stringIn); + if (mCollation != NULL && strength != kCollationCaseSensitive) { + mCollation->NormalizeString(stringNormalized); } - if (strength != kCollationCaseSensitive) { - nsString *stringLower = new nsString(stringIn); - if (NULL == stringLower) - return NS_ERROR_OUT_OF_MEMORY; - - stringLower->ToLowerCase(); - memcpy((void *) key, (void *) stringLower->GetUnicode(), byteLenIn); - delete stringLower; - } - else { - memcpy((void *) key, (void *) stringIn.GetUnicode(), byteLenIn); + // temporary implementation, call FE eventually + memcpy((void *) key, (void *) stringNormalized.GetUnicode(), byteLenIn); } - *outLen = byteLenIn; - } + *outLen = byteLenIn; return NS_OK; } diff --git a/intl/locale/src/windows/nsCollationWin.cpp b/intl/locale/src/windows/nsCollationWin.cpp index 9d376791688d..f35e3d8902c7 100644 --- a/intl/locale/src/windows/nsCollationWin.cpp +++ b/intl/locale/src/windows/nsCollationWin.cpp @@ -54,14 +54,10 @@ nsresult nsCollationWin::Initialize(nsILocale* locale) nsresult nsCollationWin::GetSortKeyLen(const nsCollationStrength strength, const nsString& stringIn, PRUint32* outLen) { - nsString stringNormalized(stringIn); - - if (mCollation != NULL && strength == kCollationCaseInSensitive) { - mCollation->NormalizeString(stringNormalized); - } + // Currently, no length change by the normalization. // API returns number of bytes when LCMAP_SORTKEY is specified *outLen = LCMapStringW(GetUserDefaultLCID(), LCMAP_SORTKEY, - (LPCWSTR) stringNormalized.GetUnicode(), (int) stringNormalized.Length(), NULL, 0); + (LPCWSTR) stringIn.GetUnicode(), (int) stringIn.Length(), NULL, 0); return NS_OK; } @@ -70,7 +66,7 @@ nsresult nsCollationWin::CreateSortKey(const nsCollationStrength strength, const nsString& stringIn, PRUint8* key, PRUint32* outLen) { int byteLen; - nsString stringNormalized(stringIn); + nsAutoString stringNormalized(stringIn); if (mCollation != NULL && strength == kCollationCaseInSensitive) { mCollation->NormalizeString(stringNormalized);