diff options
| author | Tyge <[email protected]> | 2020-04-20 10:10:56 +0200 |
|---|---|---|
| committer | Tyge <[email protected]> | 2020-04-20 10:10:56 +0200 |
| commit | 918d68b44354b38f45c796d2987b9e80a6566c3a (patch) | |
| tree | 8ba70babf704de8ed2bfd24afde337fe4f9d545a | |
| parent | 7484e04b9a395c3334ff5a44018fa60692bdd78c (diff) | |
| download | STC-modified-918d68b44354b38f45c796d2987b9e80a6566c3a.tar.gz STC-modified-918d68b44354b38f45c796d2987b9e80a6566c3a.zip | |
Small opt. in cslist, update readme.md
| -rw-r--r-- | README.md | 4 | ||||
| -rw-r--r-- | stc/cdefs.h | 4 | ||||
| -rw-r--r-- | stc/cslist.h | 3 |
3 files changed, 5 insertions, 6 deletions
@@ -96,10 +96,10 @@ int main() { cmap_si_put(&nums, "Groovy", 200); // overwrite previous
// iterate the map:
- for (cmap_si_iter_t i = cmap_si_begin(nums); i.item != cmap_si_end(nums).item; i = cmap_si_next(i))
+ for (cmap_si_iter_t i = cmap_si_begin(&nums); i.item; i = cmap_si_next(i))
printf("%s: %d\n", i.item->key.str, i.item->value);
- // or rather use the short form:
+ // or rather use the shorter form:
c_foreach (i, cmap_si, nums)
printf("%s: %d\n", i.item->key.str, i.item->value);
diff --git a/stc/cdefs.h b/stc/cdefs.h index bf010db9..3aa8136e 100644 --- a/stc/cdefs.h +++ b/stc/cdefs.h @@ -53,8 +53,8 @@ #define c_defaultEquals(x, y) (memcmp(x, y, sizeof(*(y))) == 0)
#define c_defaultDestroy(p) ((void)0)
-#define c_foreach(it, ctag, con) \
- for (ctag##_iter_t it = ctag##_begin(&con); it.item; it = ctag##_next(it))
+#define c_foreach(it, prefix, container) \
+ for (prefix##_iter_t it = prefix##_begin(&container); it.item; it = prefix##_next(it))
/* One-byte-at-a-time hash based on Murmur's mix */
static inline uint32_t c_defaultHash(const void *data, size_t len) {
diff --git a/stc/cslist.h b/stc/cslist.h index b5674722..dd321f00 100644 --- a/stc/cslist.h +++ b/stc/cslist.h @@ -114,8 +114,7 @@ \ static inline cslist_##tag##_iter_t \ cslist_##tag##_next(cslist_##tag##_iter_t it) { \ - if ((it.item = it.item->next) == (*it._last)->next) \ - it.item = NULL; \ + it.item = it.item == *it._last ? NULL : it.item->next; \ return it; \ } \ \ |
