X-Git-Url: http://git.thejh.net/?p=libjh.git;a=blobdiff_plain;f=string.c;h=5ef61b92e385a577ed466f568117a824fb4bc5df;hp=c91e6d221bfc2a383c1b530be256aaaafe809199;hb=8ca8922a920669bdaa388a3c8e72a983da91e2e0;hpb=3b41b5c082c2c3719fbbcfc4e381fee04879dc1d diff --git a/string.c b/string.c index c91e6d2..5ef61b9 100644 --- a/string.c +++ b/string.c @@ -2,6 +2,8 @@ // This code is licensed under the AGPLv3. #include +#include +HEADER #include HEADER #define streq(a,b) (!strcmp((a),(b))) @@ -14,6 +16,112 @@ PUBLIC_FN int count_char_occurences(char *s, char c) { return n; } +// For big buffers. +PUBLIC_FN size_t count_char_occurences_in_buf(char *b, size_t bl, char c) { + char *be = b+bl; + size_t res = 0; + + #ifdef __SSE2__ + #include + + // do it the simple way until we get to the next 16-byte-aligned address + while ((((uint64_t)b)&0xf) && b + + // do it the simple way until we get to the next 16-byte-aligned address + while ((((uint64_t)b)&0xf) && b