diff options
| author | Tyge Løvset <[email protected]> | 2021-07-17 12:26:25 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2021-07-17 12:26:25 +0200 |
| commit | 1220c21ec690acedfbd2c956b360947a95744292 (patch) | |
| tree | 6f8b4775557eb7f7d6edd7e5d0318ca53ada634a /include | |
| parent | d3ee4ed5d2a76d12e7c905b7aa7e1e7c87a49119 (diff) | |
| download | STC-modified-1220c21ec690acedfbd2c956b360947a95744292.tar.gz STC-modified-1220c21ec690acedfbd2c956b360947a95744292.zip | |
More refactoring. Added others/sstr.h - future short string optimized (SSO) string.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 26 | ||||
| -rw-r--r-- | include/stc/cmap.h | 4 |
2 files changed, 17 insertions, 13 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h index 7678a21d..48fae679 100644 --- a/include/stc/ccommon.h +++ b/include/stc/ccommon.h @@ -53,12 +53,13 @@ /* Macro overloading feature support based on: https://rextester.com/ONP80107 */
#define c_MACRO_OVERLOAD(name, ...) \
- _c_SELECT(name, _c_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
-#define _c_SELECT(name, num) _c_CONCAT(name ## _, num)
-#define _c_CONCAT(a, b) a ## b
-#define _c_NUM_ARGS(...) _c_APPLY_ARG_N((__VA_ARGS__, _c_RSEQ_N))
-#define _c_APPLY_ARG_N(args) _c_EXPAND(_c_ARG_N args)
-#define _c_EXPAND(...) __VA_ARGS__
+ c_SELECT(name, c_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
+#define c_SELECT(name, num) c_CONCAT(name ## _, num)
+#define c_CONCAT(a, b) a ## b
+#define c_EXPAND(...) __VA_ARGS__
+#define c_NUM_ARGS(...) _c_APPLY_ARG_N((__VA_ARGS__, _c_RSEQ_N))
+
+#define _c_APPLY_ARG_N(args) c_EXPAND(_c_ARG_N args)
#define _c_RSEQ_N 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, \
16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0
#define _c_ARG_N(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, \
@@ -69,8 +70,6 @@ #define c_container_of(ptr, type, member) \
((type *)((char *)(ptr) - offsetof(type, member)))
-#define c_struct(S) typedef struct S S; struct S
-#define c_arg(...) __VA_ARGS__
#if __cplusplus
#define c_new(T) static_cast<T*>(c_malloc(sizeof(T)))
#define c_new_n(T, n) static_cast<T*>(c_malloc(sizeof(T)*(n)))
@@ -135,9 +134,14 @@ #define c_fordefer(...) for (int _c_ii = 0; !_c_ii; ++_c_ii, __VA_ARGS__)
#define c_forvar_initdel(...) c_MACRO_OVERLOAD(c_forvar_initdel, __VA_ARGS__)
-#define c_forvar_initdel_2(CX, a) c_forvar(CX a = CX##_init(), CX##_del(&a))
-#define c_forvar_initdel_3(CX, a, b) c_forvar(c_arg(CX a = CX##_init(), b = CX##_init()), CX##_del(&b), CX##_del(&a))
-#define c_forvar_initdel_4(CX, a, b, c) c_forvar(c_arg(CX a = CX##_init(), b = CX##_init(), c = CX##_init()), CX##_del(&c), CX##_del(&b), CX##_del(&a))
+#define c_forvar_initdel_2(CX, a) \
+ c_forvar(CX a = CX##_init(), CX##_del(&a))
+#define c_forvar_initdel_3(CX, a, b) \
+ c_forvar(c_EXPAND(CX a = CX##_init(), b = CX##_init()), \
+ CX##_del(&b), CX##_del(&a))
+#define c_forvar_initdel_4(CX, a, b, c) \
+ c_forvar(c_EXPAND(CX a = CX##_init(), b = CX##_init(), c = CX##_init()), \
+ CX##_del(&c), CX##_del(&b), CX##_del(&a))
#define c_forbuffer(b, type, n) c_forbuffer_N(b, type, n, 256)
#define c_forbuffer_N(b, type, n, BYTES) \
diff --git a/include/stc/cmap.h b/include/stc/cmap.h index 737e0dab..89975374 100644 --- a/include/stc/cmap.h +++ b/include/stc/cmap.h @@ -368,7 +368,7 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ CX##_bucket_(const CX* self, const CX##_rawkey_t* rkeyptr) { \
const uint64_t _hash = keyHashRaw(rkeyptr, sizeof *rkeyptr); \
uint_fast8_t _hx; size_t _cap = self->bucket_count; \
- chash_bucket_t b = {_c_SELECT(fastrange,CMAP_SIZE_T)(_hash, _cap), (uint_fast8_t)(_hash | 0x80)}; \
+ chash_bucket_t b = {c_SELECT(fastrange,CMAP_SIZE_T)(_hash, _cap), (uint_fast8_t)(_hash | 0x80)}; \
const uint8_t* _hashx = self->_hashx; \
while ((_hx = _hashx[b.idx])) { \
if (_hx == b.hx) { \
@@ -444,7 +444,7 @@ STC_INLINE size_t fastrange_uint64_t(uint64_t x, uint64_t n) \ if (! _hashx[j]) \
break; \
CX##_rawkey_t _raw = keyToRaw(KEY_REF_##C(_slot+j)); \
- k = _c_SELECT(fastrange,CMAP_SIZE_T)(keyHashRaw(&_raw, sizeof _raw), _cap); \
+ k = c_SELECT(fastrange,CMAP_SIZE_T)(keyHashRaw(&_raw, sizeof _raw), _cap); \
if ((j < i) ^ (k <= i) ^ (k > j)) /* is k outside (i, j]? */ \
memcpy((void *) &_slot[i], &_slot[j], sizeof *_slot), _hashx[i] = _hashx[j], i = j; \
} \
|
