summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-02-18 19:07:32 +0100
committerTyge Løvset <[email protected]>2021-02-18 19:07:32 +0100
commitdacb3c303185ad3625522bd80a827af5a258b711 (patch)
tree9217be16b7ffe595248ecc7ce694990388c5d04b
parentc6b16f5c3a84e94028075f4a02ca400f91978171 (diff)
downloadSTC-modified-dacb3c303185ad3625522bd80a827af5a258b711.tar.gz
STC-modified-dacb3c303185ad3625522bd80a827af5a258b711.zip
Minor cleanup
-rw-r--r--examples/list_erase.c26
-rw-r--r--stc/cmap.h12
-rw-r--r--stc/cstr.h12
3 files changed, 17 insertions, 33 deletions
diff --git a/examples/list_erase.c b/examples/list_erase.c
index c974de74..d0bdc2df 100644
--- a/examples/list_erase.c
+++ b/examples/list_erase.c
@@ -6,19 +6,19 @@ using_clist(i, int);
int main ()
{
- c_init (clist_i, L, {10, 20, 30, 40, 50});
- clist_i_iter_t end;
- // 10 20 30 40 50
- clist_i_iter_t it = clist_i_begin(&L); // ^
- it = clist_i_erase_after(&L, it); // 10 30 40 50
- // ^
- end = clist_i_end(&L); //
- it = clist_i_erase_range_after(&L, it, end); // 10 30
- // ^
+ c_init (clist_i, L, {10, 20, 30, 40, 50});
+ clist_i_iter_t end;
+ // 10 20 30 40 50
+ clist_i_iter_t it = clist_i_begin(&L); // ^
+ it = clist_i_erase_after(&L, it); // 10 30 40 50
+ // ^
+ end = clist_i_end(&L); //
+ it = clist_i_erase_range_after(&L, it, end); // 10 30
+ // ^
- printf("mylist contains:");
- c_foreach (x, clist_i, L) printf(" %d", *x.ref);
- puts("");
+ printf("mylist contains:");
+ c_foreach (x, clist_i, L) printf(" %d", *x.ref);
+ puts("");
- clist_i_del(&L);
+ clist_i_del(&L);
} \ No newline at end of file
diff --git a/stc/cmap.h b/stc/cmap.h
index 4e5c140a..4dc6b3ab 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -437,7 +437,7 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
C##_##X##_value_t* slot = self->table; \
uint8_t* hashx = self->_hashx; \
C##_##X##_value_del(&slot[i]); \
- do { /* delete without leaving tombstone */ \
+ for (;;) { /* delete without leaving tombstone */ \
if (++j == cap) j = 0; \
if (! hashx[j]) \
break; \
@@ -445,7 +445,7 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
k = chash_reduce(keyHashRaw(&r, sizeof(RawKey)), cap); \
if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ \
slot[i] = slot[j], hashx[i] = hashx[j], i = j; \
- } while (true); \
+ } \
hashx[i] = 0, k = --self->size; \
if (k < cap*self->min_load_factor && k > 512) \
C##_##X##_reserve(self, k*1.2); \
@@ -454,12 +454,8 @@ enum {chash_HASH = 0x7f, chash_USED = 0x80};
STC_DEF uint64_t c_default_hash(const void *key, size_t len) {
const uint64_t m = 0xc6a4a7935bd1e995;
uint64_t k, h = m + len;
- const unsigned char *p = (const uint8_t *) key,
- *end = p + (len & ~7ull);
- for (; p != end; p += 8) {
- memcpy(&k, p, 8);
- h ^= k*m;
- }
+ const uint8_t *p = (const uint8_t *)key, *end = p + (len & ~7ull);
+ for (; p != end; p += 8) {memcpy(&k, p, 8); h ^= k*m;}
switch (len & 7) {
case 7: h ^= (uint64_t) p[6] << 48;
case 6: h ^= (uint64_t) p[5] << 40;
diff --git a/stc/cstr.h b/stc/cstr.h
index 6ab9a2d8..19c356c0 100644
--- a/stc/cstr.h
+++ b/stc/cstr.h
@@ -49,7 +49,6 @@ 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 char* c_strcopy(const char* src, char* dst, const char* dst_end, int termin);
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,17 +394,6 @@ 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 char*
-c_strcopy(const char* s, char* d, const char* d_end, int c) {
- enum {w = sizeof(uintptr_t)}; const uintptr_t z = ~(uintptr_t)0/255;
- for (uintptr_t x; d + w <= d_end; s += w, d += w) {
- memcpy(&x, s, w); /* check if x contains c: */
- if (((x - z) & ~x & z<<7) ^ (z*(uint8_t) c)) break;
- memcpy(d, &x, w);
- }
- while (d < d_end) if ((*d++ = *s++) == (uint8_t) c) return d - 1;
- return NULL;
-}
STC_DEF int
c_strncasecmp(const char* s1, const char* s2, size_t n) {