X-Git-Url: http://git.thejh.net/?p=libjh.git;a=blobdiff_plain;f=string.c;h=5ef61b92e385a577ed466f568117a824fb4bc5df;hp=21ff3a745db302663cb05b04672aa3b4e4da2952;hb=a32bce31ecf816bbf0dc3530c6e7dee1e5653ac9;hpb=e3a7f339e843d1424aef577e5634ac70343ec49c diff --git a/string.c b/string.c index 21ff3a7..5ef61b9 100644 --- a/string.c +++ b/string.c @@ -1,4 +1,9 @@ +// Copyright (2013) Jann Horn +// This code is licensed under the AGPLv3. + #include +#include +HEADER #include HEADER #define streq(a,b) (!strcmp((a),(b))) @@ -11,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