From 63806444e21d46e7873654701f5808d6c33a034d Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Mon, 12 Apr 2021 15:13:35 +0200 Subject: Fix another issue with local var in csmap_X_erase_at(), and a constness issue in csmap_erase_range(). Reduced iter size. --- stc/cmap.h | 14 +++++++------- stc/csmap.h | 14 +++++++------- stc/csptr.h | 2 +- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/stc/cmap.h b/stc/cmap.h index 59699ec7..4690b995 100644 --- a/stc/cmap.h +++ b/stc/cmap.h @@ -346,14 +346,14 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ \ STC_DEF chash_bucket_t \ CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr) { \ - const uint64_t hash = keyHashRaw(rkeyptr, sizeof(RawKey)); \ + const uint64_t hash = keyHashRaw(rkeyptr, sizeof *rkeyptr); \ uint_fast8_t sx; size_t cap = self->bucket_count; \ chash_bucket_t b = {_c_SELECT(fastrange,CMAP_SIZE_T)(hash, cap), (uint_fast8_t)(hash | 0x80)}; \ const uint8_t* hashx = self->_hashx; \ while ((sx = hashx[b.idx])) { \ if (sx == b.hx) { \ - RawKey r = keyToRaw(KEY_REF_##C(self->table + b.idx)); \ - if (keyEqualsRaw(&r, rkeyptr)) break; \ + CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(self->table + b.idx)); \ + if (keyEqualsRaw(&raw, rkeyptr)) break; \ } \ if (++b.idx == cap) b.idx = 0; \ } \ @@ -415,8 +415,8 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ uint8_t* hashx = self->_hashx; \ for (size_t i = 0; i < oldcap; ++i, ++e) \ if (tmp._hashx[i]) { \ - RawKey r = keyToRaw(KEY_REF_##C(e)); \ - chash_bucket_t b = CX##_bucket_(self, &r); \ + CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(e)); \ + chash_bucket_t b = CX##_bucket_(self, &raw); \ slot[b.idx] = *e, \ hashx[b.idx] = (uint8_t) b.hx; \ } \ @@ -434,8 +434,8 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ if (++j == cap) j = 0; \ if (! hashx[j]) \ break; \ - RawKey r = keyToRaw(KEY_REF_##C(slot + j)); \ - k = _c_SELECT(fastrange,CMAP_SIZE_T)(keyHashRaw(&r, sizeof(RawKey)), cap); \ + CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(slot + j)); \ + k = _c_SELECT(fastrange,CMAP_SIZE_T)(keyHashRaw(&raw, sizeof raw), cap); \ if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ \ slot[i] = slot[j], hashx[i] = hashx[j], i = j; \ } \ diff --git a/stc/csmap.h b/stc/csmap.h index 2c0b817a..7e433c1d 100644 --- a/stc/csmap.h +++ b/stc/csmap.h @@ -171,7 +171,7 @@ struct csmap_rep { size_t root, disp, head, size, cap; void* nodes[]; }; CX##_value_t *ref; \ CX##_node_t *_d; \ int _top; \ - CX##_size_t _tn, _st[48]; \ + CX##_size_t _tn, _st[40]; \ } CX##_iter_t; \ \ STC_API CX CX##_init(void); \ @@ -359,8 +359,8 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; CX##_node_t *d = out->_d = self->nodes; \ out->_top = 0; \ while (tn) { \ - int c; RawKey rx = keyToRaw(KEY_REF_##C(&d[tn].value)); \ - if ((c = keyCompareRaw(&rx, &rkey)) < 0) \ + int c; CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(&d[tn].value)); \ + if ((c = keyCompareRaw(&raw, &rkey)) < 0) \ tn = d[tn].link[1]; \ else if (c > 0) \ { out->_st[out->_top++] = tn; tn = d[tn].link[0]; } \ @@ -501,7 +501,7 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; \ STC_DEF CX##_iter_t \ CX##_erase_at(CX* self, CX##_iter_t it) { \ - RawKey raw = keyToRaw(KEY_REF_##C(it.ref)), nxt; \ + CX##_rawkey_t raw = keyToRaw(KEY_REF_##C(it.ref)), nxt; \ CX##_next(&it); \ if (it.ref) nxt = keyToRaw(KEY_REF_##C(it.ref)); \ CX##_erase(self, raw); \ @@ -511,14 +511,14 @@ static struct csmap_rep _csmap_inits = {0, 0, 0, 0}; \ STC_DEF CX##_iter_t \ CX##_erase_range(CX* self, CX##_iter_t it1, CX##_iter_t it2) { \ - CX##_rawkey_t *arr = NULL, nxt; size_t sz=0, cap=0; \ + CX##_rawkey_t nxt, *arr = NULL; size_t sz=0, cap=0; \ for (; it1.ref != it2.ref; CX##_next(&it1), ++sz) { \ - if (sz == cap) arr = (CX##_rawkey_t*) c_realloc(arr, sizeof arr[0]*(cap = (sz + 6)*1.5)); \ + if (sz == cap) arr = (CX##_rawkey_t*) c_realloc((void *) arr, sizeof arr[0]*(cap = (sz + 6)*1.5)); \ arr[sz] = keyToRaw(KEY_REF_##C(it1.ref)); \ } \ if (it2.ref) nxt = keyToRaw(KEY_REF_##C(it2.ref)); \ for (size_t i=0; i