aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/basetypes
diff options
context:
space:
mode:
authorGravatar Hoa V. Dinh <dinh.viet.hoa@gmail.com>2015-07-06 16:10:43 -0700
committerGravatar Hoa V. Dinh <dinh.viet.hoa@gmail.com>2015-07-06 16:10:43 -0700
commitbf9061a79c7f0ee52cc781ca356a4e273a641270 (patch)
tree2514ded955da5803518995fb56b5048244b97bea /src/core/basetypes
parentd782ab69e0cad5e05c565fe1b297566ab5055c96 (diff)
Improved performance of componentsSeparatedByString()
Diffstat (limited to 'src/core/basetypes')
-rw-r--r--src/core/basetypes/MCString.cpp19
1 files changed, 19 insertions, 0 deletions
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);