adds an optimization for one-byte delimiters to sstrsplit (will take effect after planned reimplementation of sstrstr)

Mon, 20 Feb 2017 17:12:14 +0100

author
Mike Becker <universe@uap-core.de>
date
Mon, 20 Feb 2017 17:12:14 +0100
changeset 234
7a63b4986b5b
parent 233
bd58fdde142d
child 235
7cf1e41833a2

adds an optimization for one-byte delimiters to sstrsplit (will take effect after planned reimplementation of sstrstr)

ucx/string.c file | annotate | diff | comparison | revisions
--- a/ucx/string.c	Mon Feb 20 16:57:09 2017 +0100
+++ b/ucx/string.c	Mon Feb 20 17:12:14 2017 +0100
@@ -224,7 +224,20 @@
         sstr_t curpos = s;
         ssize_t j = 1;
         while (1) {
-            sstr_t match = sstrstr(curpos, d);
+            sstr_t match;
+            /* optimize for one byte delimiters */
+            if (d.length == 1) {
+                match = curpos;
+                for (size_t i = 0 ; i < curpos.length ; i++) {
+                    if (curpos.ptr[i] == *(d.ptr)) {
+                        match.ptr = curpos.ptr + i;
+                        break;
+                    }
+                    match.length--;
+                }
+            } else {
+                match = sstrstr(curpos, d);
+            }
             if (match.length > 0) {
                 /* is this our last try? */
                 if (nmax == 0 || j < nmax) {

mercurial