summaryrefslogtreecommitdiffhomepage
path: root/include/stc
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-08-10 13:43:25 +0200
committerTyge Løvset <[email protected]>2022-08-10 13:43:25 +0200
commit8eea6dfb61e9922de5940be975f4a51dcf4a62a3 (patch)
treea7f1972d8016e560019f1dcbfe7673c8b5879046 /include/stc
parent1756309078f4c09765bde898e50b8a3078cebc7d (diff)
downloadSTC-modified-8eea6dfb61e9922de5940be975f4a51dcf4a62a3.tar.gz
STC-modified-8eea6dfb61e9922de5940be975f4a51dcf4a62a3.zip
Fixed cdeq_begin(). Optimized c_foreach: only use one iter.
Diffstat (limited to 'include/stc')
-rw-r--r--include/stc/ccommon.h7
-rw-r--r--include/stc/cdeq.h2
2 files changed, 4 insertions, 5 deletions
diff --git a/include/stc/ccommon.h b/include/stc/ccommon.h
index e2c63b8c..7a60b045 100644
--- a/include/stc/ccommon.h
+++ b/include/stc/ccommon.h
@@ -157,11 +157,10 @@ STC_INLINE char* c_strnstrn(const char *s, const char *needle,
#define c_foreach(...) c_MACRO_OVERLOAD(c_foreach, __VA_ARGS__)
#define c_foreach3(it, C, cnt) \
- for (C##_iter it = C##_begin(&cnt), it##_end_ = C##_end(&cnt) \
- ; it.ref != it##_end_.ref; C##_next(&it))
+ for (C##_iter it = C##_begin(&cnt); it.ref; C##_next(&it))
#define c_foreach4(it, C, start, finish) \
- for (C##_iter it = start, it##_end_ = finish \
- ; it.ref != it##_end_.ref; C##_next(&it))
+ for (C##_iter it = start, *_end_ref = (C##_iter*)(finish).ref \
+ ; it.ref != (C##_value*)_end_ref; C##_next(&it))
#define c_forpair(key, val, C, cnt) /* structured binding */ \
for (struct {C##_iter _it; C##_value* _endref; const C##_key* key; C##_mapped* val;} \
diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h
index da7f258f..d08e0155 100644
--- a/include/stc/cdeq.h
+++ b/include/stc/cdeq.h
@@ -93,7 +93,7 @@ STC_INLINE _cx_value* _cx_memb(_back)(const _cx_self* self)
STC_INLINE void _cx_memb(_pop_front)(_cx_self* self) // == _pop() when _i_queue
{ i_keydrop(self->data); ++self->data; --cdeq_rep_(self)->size; }
STC_INLINE _cx_iter _cx_memb(_begin)(const _cx_self* self)
- { return c_make(_cx_iter){self->data}; }
+ { size_t n = cdeq_rep_(self)->size; return c_make(_cx_iter){n ? self->data : NULL, self->data + n}; }
STC_INLINE _cx_iter _cx_memb(_end)(const _cx_self* self)
{ return c_make(_cx_iter){NULL, self->data + cdeq_rep_(self)->size}; }
STC_INLINE void _cx_memb(_next)(_cx_iter* it) { if (++it->ref == it->_end) it->ref = NULL; }