diff options
| author | Tyge Løvset <[email protected]> | 2022-10-28 10:00:35 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-10-28 10:00:35 +0200 |
| commit | d63c37c043024854cfb4b63495e8f5ca3fc03ecd (patch) | |
| tree | 14c781006a0575c7f2b7515dc5742daaeb916973 /include | |
| parent | 0243b64f830f55b924274cbc63f5dd1ed518c26f (diff) | |
| download | STC-modified-d63c37c043024854cfb4b63495e8f5ca3fc03ecd.tar.gz STC-modified-d63c37c043024854cfb4b63495e8f5ca3fc03ecd.zip | |
Renamed some semi-internal functions which appeared to be macros by their name.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/alt/cstr.h | 4 | ||||
| -rw-r--r-- | include/stc/ccommon.h | 22 | ||||
| -rw-r--r-- | include/stc/cstr.h | 6 | ||||
| -rw-r--r-- | include/stc/csview.h | 6 |
4 files changed, 19 insertions, 19 deletions
diff --git a/include/stc/alt/cstr.h b/include/stc/alt/cstr.h index fd1d5bb1..17548b5d 100644 --- a/include/stc/alt/cstr.h +++ b/include/stc/alt/cstr.h @@ -176,7 +176,7 @@ STC_INLINE bool cstr_eq(const cstr* x, const cstr* y) { return xs == ys && !memcmp(x->str, y->str, xs); } STC_INLINE uint64_t cstr_hash(const cstr *self) { - return c_fasthash(self->str, _cstr_p(self)->size); + return cfasthash(self->str, _cstr_p(self)->size); } STC_INLINE void @@ -323,7 +323,7 @@ cstr_replace_sv(csview str, csview find, csview repl, unsigned count) { size_t from = 0; char* res; if (count == 0) count = ~0; if (find.size) - while (count-- && (res = c_strnstrn(str.str + from, find.str, str.size - from, find.size))) { + while (count-- && (res = cstrnstrn(str.str + from, find.str, str.size - from, find.size))) { const size_t pos = res - str.str; cstr_append_n(&out, str.str + from, pos - from); cstr_append_n(&out, repl.str, repl.size); diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 9395171f..65d90987 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -98,7 +98,7 @@ #define c_default_less(x, y) (*(x) < *(y)) #define c_default_eq(x, y) (*(x) == *(y)) #define c_memcmp_eq(x, y) (memcmp(x, y, sizeof *(x)) == 0) -#define c_default_hash(x) c_fasthash(x, sizeof *(x)) +#define c_default_hash(x) cfasthash(x, sizeof *(x)) #define c_default_clone(v) (v) #define c_default_toraw(vp) (*(vp)) @@ -118,7 +118,7 @@ typedef const char* crawstr; #define crawstr_cmp(xp, yp) strcmp(*(xp), *(yp)) -#define crawstr_hash(p) c_strhash(*(p)) +#define crawstr_hash(p) cstrhash(*(p)) #define c_strlen_lit(literal) (sizeof "" literal - 1U) #define c_sv(...) c_MACRO_OVERLOAD(c_sv, __VA_ARGS__) @@ -130,7 +130,7 @@ typedef const char* crawstr; #define _c_ROTL(x, k) (x << (k) | x >> (8*sizeof(x) - (k))) -STC_INLINE uint64_t c_fasthash(const void* key, size_t len) { +STC_INLINE uint64_t cfasthash(const void* key, size_t len) { const uint8_t *x = (const uint8_t*) key; uint64_t u8, h = 1; size_t n = len >> 3; uint32_t u4; @@ -148,18 +148,18 @@ STC_INLINE uint64_t c_fasthash(const void* key, size_t len) { return _c_ROTL(h, 26) ^ h; } -STC_INLINE uint64_t c_strhash(const char *str) - { return c_fasthash(str, strlen(str)); } +STC_INLINE uint64_t cstrhash(const char *str) + { return cfasthash(str, strlen(str)); } -STC_INLINE char* c_strnstrn(const char *s, const char *needle, - size_t slen, const size_t nlen) { - if (!nlen) return (char *)s; +STC_INLINE char* cstrnstrn(const char *str, const char *needle, + size_t slen, const size_t nlen) { + if (!nlen) return (char *)str; if (nlen > slen) return NULL; slen -= nlen; do { - if (*s == *needle && !memcmp(s, needle, nlen)) - return (char *)s; - ++s; + if (*str == *needle && !memcmp(str, needle, nlen)) + return (char *)str; + ++str; } while (slen--); return NULL; } diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 3605bab8..5f6e19a8 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -413,11 +413,11 @@ STC_API uint64_t cstr_hash(const cstr *self); STC_DEF uint64_t cstr_hash(const cstr *self) { csview sv = cstr_sv(self); - return c_fasthash(sv.str, sv.size); + return cfasthash(sv.str, sv.size); } STC_DEF size_t cstr_find_sv(const cstr* self, csview search) { - char* res = c_strnstrn(cstr_str(self), search.str, cstr_size(self), search.size); + char* res = cstrnstrn(cstr_str(self), search.str, cstr_size(self), search.size); return res ? res - cstr_str(self) : cstr_npos; } @@ -540,7 +540,7 @@ cstr_replace_sv(csview in, csview search, csview repl, unsigned count) { size_t from = 0; char* res; if (!count) count = ~0; if (search.size) - while (count-- && (res = c_strnstrn(in.str + from, search.str, in.size - from, search.size))) { + while (count-- && (res = cstrnstrn(in.str + from, search.str, in.size - from, search.size))) { const size_t pos = res - in.str; cstr_append_n(&out, in.str + from, pos - from); cstr_append_n(&out, repl.str, repl.size); diff --git a/include/stc/csview.h b/include/stc/csview.h index 566534cc..99a676a6 100644 --- a/include/stc/csview.h +++ b/include/stc/csview.h @@ -160,12 +160,12 @@ STC_API uint64_t csview_hash(const csview *self); #if defined(i_implement) || defined(i_extern) STC_DEF size_t csview_find(csview sv, csview search) { - char* res = c_strnstrn(sv.str, search.str, sv.size, search.size); + char* res = cstrnstrn(sv.str, search.str, sv.size, search.size); return res ? res - sv.str : csview_npos; } STC_DEF uint64_t csview_hash(const csview *self) - { return c_fasthash(self->str, self->size); } + { return cfasthash(self->str, self->size); } STC_DEF csview csview_substr_ex(csview sv, intptr_t pos, size_t n) { if (pos < 0) { @@ -191,7 +191,7 @@ STC_DEF csview csview_slice_ex(csview sv, intptr_t p1, intptr_t p2) { STC_DEF csview csview_token(csview sv, csview sep, size_t* start) { csview slice = {sv.str + *start, sv.size - *start}; - const char* res = c_strnstrn(slice.str, sep.str, slice.size, sep.size); + const char* res = cstrnstrn(slice.str, sep.str, slice.size, sep.size); csview tok = {slice.str, res ? res - slice.str : slice.size}; *start += tok.size + sep.size; return tok; |
