From: VMware, Inc <> Date: Mon, 20 Dec 2010 21:57:01 +0000 (-0800) Subject: lib/unicode: optimize/simplify Unicode_FindLastSubstrInRange X-Git-Tag: 2010.12.19-339835~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63fa51d4a3dde82203372667ff68fc1550ee35d6;p=thirdparty%2Fopen-vm-tools.git lib/unicode: optimize/simplify Unicode_FindLastSubstrInRange It's a bit complex. Make the code faster and simpler. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/lib/unicode/unicodeSimpleOperations.c b/open-vm-tools/lib/unicode/unicodeSimpleOperations.c index bfd0693f8..5e52ffb11 100644 --- a/open-vm-tools/lib/unicode/unicodeSimpleOperations.c +++ b/open-vm-tools/lib/unicode/unicodeSimpleOperations.c @@ -323,8 +323,8 @@ Unicode_FindSubstrInRange(ConstUnicode str, // IN: for (index = strStart; index <= (strStart + strLength - strToFindLength); index++) { - Bool match = FALSE; UnicodeIndex i; + Bool match = FALSE; UnicodeIndex indexSrc = index; UnicodeIndex indexSrch = strToFindStart; @@ -391,7 +391,6 @@ Unicode_FindLastSubstrInRange(ConstUnicode str, // IN: UnicodeIndex strToFindLength) // IN: { UnicodeIndex index; - UnicodeIndex strToFindEnd; uint32 *utf32Source = NULL; uint32 *utf32Search = NULL; @@ -446,27 +445,25 @@ Unicode_FindLastSubstrInRange(ConstUnicode str, // IN: * to be searched. */ - strToFindEnd = strToFindStart + strToFindLength - 1; - - for (index = strStart + strLength - 1; index >= strStart; index--) { - if (utf32Source[index] == utf32Search[strToFindEnd]) { - UnicodeIndex strSubOffset = index; - UnicodeIndex strToFindSubOffset = strToFindEnd; - - while (TRUE) { - if (strToFindSubOffset == strToFindStart) { - index = strSubOffset; // Found the substring. - goto bail; - } + for (index = strStart + strLength - strToFindLength; + index >= strStart; + index--) { + UnicodeIndex i; + Bool match = FALSE; + UnicodeIndex indexSrc = index; + UnicodeIndex indexSrch = strToFindStart; - strToFindSubOffset--; - strSubOffset--; + for (i = 0; i < strToFindLength; i++) { + match = (utf32Source[indexSrc++] == utf32Search[indexSrch++]); - if (utf32Source[strSubOffset] != utf32Search[strToFindSubOffset]) { - break; - } + if (!match) { + break; } } + + if (match) { + goto bail; + } } index = UNICODE_INDEX_NOT_FOUND;