diff options
| author | Tyge Løvset <[email protected]> | 2021-02-16 11:09:43 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-02-16 11:09:43 +0100 |
| commit | 8114c84436424618f10bbfdab3bf9635f2781196 (patch) | |
| tree | f6848a57aa59e1d91cd8a936681c3b82a23746ed | |
| parent | bae3c479b2f1ff807553d1b9ff3b561cc4444054 (diff) | |
| download | STC-modified-8114c84436424618f10bbfdab3bf9635f2781196.tar.gz STC-modified-8114c84436424618f10bbfdab3bf9635f2781196.zip | |
Tweaked.
| -rw-r--r-- | stc/cstr.h | 11 |
1 files changed, 6 insertions, 5 deletions
@@ -398,13 +398,14 @@ STC_DEF void* c_memccpy(void* dst, const void* src, int c, size_t n) {
enum {w = sizeof(uintptr_t)};
#define _mc_z (~(uintptr_t)0/255)
- const uint8_t* s = (const uint8_t *) src; uint8_t *d = (uint8_t *) dst, *e = d + n;
- 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
+ const uint8_t* s = (const uint8_t *) src;
+ uint8_t *d = (uint8_t *) dst, *end = d + n;
+ for (uintptr_t x; d + w <= end; s += w, d += w) {
+ memcpy(&x, s, w); /* check if x contains c: */
+ if (((x - _mc_z) & ~x & _mc_z*128) ^ (_mc_z*(uint8_t) c)) break;
memcpy(d, &x, w);
}
- while (d < e) if ((*d++ = *s++) == (uint8_t) c) return d;
+ while (d < end) if ((*d++ = *s++) == (uint8_t) c) return d;
return NULL;
}
|
