diff --git a/icu4c/source/i18n/ucol.cpp b/icu4c/source/i18n/ucol.cpp index 5bcc9fe5a89..43acc07fc65 100644 --- a/icu4c/source/i18n/ucol.cpp +++ b/icu4c/source/i18n/ucol.cpp @@ -2731,21 +2731,21 @@ ucol_strcoll( const UCollator *coll, const UChar *pSrcEnd = source + sourceLength; const UChar *pTargEnd = target + targetLength; - int32_t equalLength = 0; + int32_t equalLength; // Scan while the strings are bitwise ==, or until one is exhausted. for (;;) { if (pSrc == pSrcEnd || pTarg == pTargEnd) break; - if (*pSrc != *pTarg) - break; if (*pSrc == 0 && (sourceLength == -1 || targetLength == -1)) break; - equalLength++; + if (*pSrc != *pTarg) + break; pSrc++; pTarg++; } - + equalLength = pSrc - source; + // If we made it all the way through both strings, we are done. They are == if ((pSrc ==pSrcEnd || (pSrcEnd