From bf9061a79c7f0ee52cc781ca356a4e273a641270 Mon Sep 17 00:00:00 2001 From: "Hoa V. Dinh" Date: Mon, 6 Jul 2015 16:10:43 -0700 Subject: Improved performance of componentsSeparatedByString() --- src/core/basetypes/MCString.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/core/basetypes/MCString.cpp b/src/core/basetypes/MCString.cpp index 7d7a740e..7c6539ac 100644 --- a/src/core/basetypes/MCString.cpp +++ b/src/core/basetypes/MCString.cpp @@ -2244,10 +2244,29 @@ Array * String::componentsSeparatedByString(String * separator) p = mUnicodeChars; while (1) { UChar * location; +#if 0 location = u_strstr(p, separator->unicodeCharacters()); if (location == NULL) { break; } +#else + int remaining = length() - (int) (p - mUnicodeChars); + location = NULL; + while (location == NULL) { + location = (UChar *) memmem(p, remaining * sizeof(UChar), separator->unicodeCharacters(), separator->length() * sizeof(UChar)); + if (location == NULL) { + break; + } + // If it's odd, it's an invalid location. Keep looking for the pattern. + if (((char *) location - (char *) p) % sizeof(UChar) != 0) { + p = (UChar *) (((char *) location) + 1); + location = NULL; + } + } + if (location == NULL) { + break; + } +#endif unsigned int length = (unsigned int) (location - p); String * value = new String(p, length); -- cgit v1.2.3