diff options
Diffstat (limited to 'zap/src/fndbyte.c')
-rw-r--r-- | zap/src/fndbyte.c | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/zap/src/fndbyte.c b/zap/src/fndbyte.c index 3283eec..e6e6070 100644 --- a/zap/src/fndbyte.c +++ b/zap/src/fndbyte.c @@ -6,18 +6,20 @@ #include <zap/priv.h> +#include <zap/mem.h> + #include <stddef.h> #include <stdint.h> -#if defined(zap_priv_fastimpl) +#if zap_priv_fastimpl __asm__ ( ".globl zap_fndbyte\n" "zap_fndbyte:\n" /* - void const * ptr - size_t num - uint_least8_t byte + void const * pos + size_t num + unsigned char byte */ #if defined(sus_arch_amd64) /* rax: Address of the current element. */ @@ -68,10 +70,11 @@ __asm__ ( #endif ); #else -size_t zap_fndbyte(void const * const _ptr,size_t const _num,uint_least8_t const _byte) { - uint_least8_t const * ptr = (uint_least8_t const *)_ptr; - uint_least8_t const * const afterbuf = ptr + _num; - for (;ptr != afterbuf;++ptr) {sus_unlikely (*ptr == _byte) {return ptr - (uint_least8_t const *)_ptr;}} +size_t zap_fndbyte(void const * const _ptr,size_t const _num,unsigned char const _byte) { + unsigned char const * startpos = _ptr; + unsigned char const * pos = startpos; + unsigned char const * const afterbuf = pos + _num; + for (;pos != afterbuf;++pos) {sus_unlikely (*pos == _byte) {return pos - startpos;}} return SIZE_MAX; } #endif |