diff options
| -rw-r--r-- | stc/cstr.h | 14 |
1 files changed, 6 insertions, 8 deletions
@@ -49,7 +49,7 @@ STC_API size_t cstr_find(cstr_t s, const char* needle); STC_API size_t cstr_find_n(cstr_t s, const char* needle, size_t pos, size_t nlen);
STC_API size_t cstr_ifind_n(cstr_t s, const char* needle, size_t pos, size_t nlen);
-STC_API void* c_memccpy(void* restrict dst, const void* restrict src, int c, size_t n);
+STC_API void* c_memccpy(void* dst, const void* src, int c, size_t n);
STC_API int c_strncasecmp(const char* s1, const char* s2, size_t n);
STC_API char* c_strnfind(const char* s, const char* needle, size_t nmax);
STC_API char* c_istrnfind(const char* s, const char* needle, size_t nmax);
@@ -395,15 +395,13 @@ cstr_ifind_n(cstr_t s, const char* needle, size_t pos, size_t nlen) { /* http://graphics.stanford.edu/~seander/bithacks.html#ZeroInWord */
STC_DEF void*
-c_memccpy(void* restrict dst, const void* restrict src, int c, size_t n) {
+c_memccpy(void* dst, const void* src, int c, size_t n) {
enum {w = sizeof(uintptr_t)};
- #define __z (~(uintptr_t)0/255)
+ #define _mc_z (~(uintptr_t)0/255)
const uint8_t* s = (const uint8_t *) src; uint8_t *d = (uint8_t *) dst, *e = d + n;
- const uint8_t *align = (const uint8_t *)(((uintptr_t)s + w-1) & ~(w-1));
- while (s != align) if ((*d++ = *s++) == (uint8_t) c) return d;
- for (; d + w <= e; s += w, d += w) {
- const uintptr_t x = *(uintptr_t *) s;
- if (((x - __z) & ~x & __z*128) ^ (__z * (uint8_t) c)) break; /* hasvalue */
+ for (uintptr_t x; d + (w*2) <= e; s += w, d += w) {
+ memcpy(&x, s, w);
+ if (((x - _mc_z) & ~x & _mc_z*128) ^ (_mc_z*(uint8_t) c)) break; // hasvalue
memcpy(d, &x, w);
}
while (d < e) if ((*d++ = *s++) == (uint8_t) c) return d;
|
