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
     1.1 --- a/ucx/string.c	Mon Feb 20 16:57:09 2017 +0100
     1.2 +++ b/ucx/string.c	Mon Feb 20 17:12:14 2017 +0100
     1.3 @@ -224,7 +224,20 @@
     1.4          sstr_t curpos = s;
     1.5          ssize_t j = 1;
     1.6          while (1) {
     1.7 -            sstr_t match = sstrstr(curpos, d);
     1.8 +            sstr_t match;
     1.9 +            /* optimize for one byte delimiters */
    1.10 +            if (d.length == 1) {
    1.11 +                match = curpos;
    1.12 +                for (size_t i = 0 ; i < curpos.length ; i++) {
    1.13 +                    if (curpos.ptr[i] == *(d.ptr)) {
    1.14 +                        match.ptr = curpos.ptr + i;
    1.15 +                        break;
    1.16 +                    }
    1.17 +                    match.length--;
    1.18 +                }
    1.19 +            } else {
    1.20 +                match = sstrstr(curpos, d);
    1.21 +            }
    1.22              if (match.length > 0) {
    1.23                  /* is this our last try? */
    1.24                  if (nmax == 0 || j < nmax) {

mercurial