# HG changeset patch # User Mike Becker # Date 1737898627 -3600 # Node ID 747c4baed44f3307c2bf500165f7c22d2317c3a3 # Parent 4f02c1101f2ee9382d620b2220144f6430a23a4d improve cx_strchr() diff -r 4f02c1101f2e -r 747c4baed44f src/string.c --- a/src/string.c Sun Jan 26 14:23:13 2025 +0100 +++ b/src/string.c Sun Jan 26 14:37:07 2025 +0100 @@ -220,14 +220,9 @@ cxstring string, int chr ) { - chr = 0xFF & chr; - // TODO: improve by comparing multiple bytes at once - for (size_t i = 0; i < string.length; i++) { - if (string.ptr[i] == chr) { - return cx_strsubs(string, i); - } - } - return (cxstring) {NULL, 0}; + char *ret = memchr(string.ptr, 0xFF & chr, string.length); + if (ret == NULL) return (cxstring) {NULL, 0}; + return (cxstring) {ret, string.length - (ret - string.ptr)}; } cxmutstr cx_strchr_m(