summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2020-10-01 20:00:23 +0200
committerTyge Løvset <[email protected]>2020-10-01 20:00:23 +0200
commit08617f84d9efa5bc724e3e5f767a93b06d0d2841 (patch)
tree63e28d1c102820f23670c7396caf4cc678e2a9b4
parentd65f4e23190e34bc357c61824df45ea0f88b84a8 (diff)
downloadSTC-modified-08617f84d9efa5bc724e3e5f767a93b06d0d2841.tar.gz
STC-modified-08617f84d9efa5bc724e3e5f767a93b06d0d2841.zip
Minor refactoring.
-rw-r--r--stc/cdefs.h12
-rw-r--r--stc/clist.h2
-rw-r--r--stc/cmap.h4
3 files changed, 10 insertions, 8 deletions
diff --git a/stc/cdefs.h b/stc/cdefs.h
index 1dcfeaef..45692286 100644
--- a/stc/cdefs.h
+++ b/stc/cdefs.h
@@ -96,13 +96,19 @@ enum {_c_max_buffer = 512};
#define c_push_items(self, ctype, ...) do { \
const ctype##_input_t __arr[] = __VA_ARGS__; \
- ctype##_push_n(self, __arr, sizeof(__arr)/sizeof(__arr[0])); \
+ ctype##_push_n(self, __arr, sizeof __arr/sizeof *__arr); \
+} while (0)
+
+#define c_emplace_items(self, ctype, ...) do { \
+ const ctype##_input_t __arr[] = __VA_ARGS__; \
+ for (size_t __i=0;__i<sizeof __arr/sizeof *__arr; ++__i) \
+ ctype##_emplace(self, __arr[__i]); \
} while (0)
#define c_del(ctype, ...) do { \
ctype##_t* __arr[] = {__VA_ARGS__}; \
- for (size_t i=0; i<sizeof(__arr)/sizeof(__arr[0]); ++i) \
- ctype##_del(__arr[i]); \
+ for (size_t __i=0; __i<sizeof __arr/sizeof *__arr; ++__i) \
+ ctype##_del(__arr[__i]); \
} while (0)
#endif
diff --git a/stc/clist.h b/stc/clist.h
index 67ed0586..ef894cb3 100644
--- a/stc/clist.h
+++ b/stc/clist.h
@@ -92,7 +92,7 @@
ctype* __self = self; \
ctype##_iter_t __pos = pos; \
const ctype##_input_t __arr[] = __VA_ARGS__; \
- for (size_t __i=0; __i<sizeof(__arr)/sizeof(__arr[0]); ++__i) \
+ for (size_t __i=0; __i<sizeof __arr/sizeof *__arr; ++__i) \
__pos = ctype##_emplace_after(__self, __pos, __arr[__i]); \
} while (0)
diff --git a/stc/cmap.h b/stc/cmap.h
index a263cce1..e0b85d99 100644
--- a/stc/cmap.h
+++ b/stc/cmap.h
@@ -64,10 +64,6 @@ int main(void) {
ctype##_result_t __r = ctype##_insert_key_(self, key); \
if (__r.second) __r.first->second = val; \
} while (0)
-#define c_insert_items(self, ctype, ...) do { \
- const ctype##_input_t __arr[] = __VA_ARGS__; \
- for (size_t i=0;i<sizeof(__arr)/sizeof(__arr[0]); ++i) ctype##_insert(self, __arr[i]); \
-} while (0)
/* https://lemire.me/blog/2016/06/27/a-fast-alternative-to-the-modulo-reduction */
#define chash_reduce(x, N) ((uint32_t) (((uint64_t) (x) * (N)) >> 32))