]> git.kaiwu.me - klib.git/commitdiff
Apply memchr optimisation in the general delimiter case too
authorJohn Marshall <jmarshall@hey.com>
Wed, 20 Sep 2023 20:08:05 +0000 (08:08 +1200)
committerJohn Marshall <jmarshall@hey.com>
Wed, 20 Sep 2023 20:08:05 +0000 (08:08 +1200)
kseq.h

diff --git a/kseq.h b/kseq.h
index 99c9ea216dbc49e326dc35272a71a90d6aebfca8..81cc774b6c24ecd21ec152f3ef7364ceb2fbb063 100644 (file)
--- a/kseq.h
+++ b/kseq.h
@@ -111,8 +111,8 @@ typedef struct __kstring_t {
                                unsigned char *sep = memchr(ks->buf + ks->begin, '\n', ks->end - ks->begin); \
                                i = sep != NULL ? sep - ks->buf : ks->end;                              \
                        } else if (delimiter > KS_SEP_MAX) {                                            \
-                               for (i = ks->begin; i < ks->end; ++i)                                   \
-                                       if (ks->buf[i] == delimiter) break;                                     \
+                               unsigned char *sep = memchr(ks->buf + ks->begin, delimiter, ks->end - ks->begin); \
+                               i = sep != NULL ? sep - ks->buf : ks->end;                              \
                        } else if (delimiter == KS_SEP_SPACE) {                                         \
                                for (i = ks->begin; i < ks->end; ++i)                                   \
                                        if (isspace(ks->buf[i])) break;                                         \