diff options
| author | Tyge Løvset <[email protected]> | 2022-08-10 13:43:25 +0200 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-08-10 13:43:25 +0200 |
| commit | 8eea6dfb61e9922de5940be975f4a51dcf4a62a3 (patch) | |
| tree | a7f1972d8016e560019f1dcbfe7673c8b5879046 /include | |
| parent | 1756309078f4c09765bde898e50b8a3078cebc7d (diff) | |
| download | STC-modified-8eea6dfb61e9922de5940be975f4a51dcf4a62a3.tar.gz STC-modified-8eea6dfb61e9922de5940be975f4a51dcf4a62a3.zip | |
Fixed cdeq_begin(). Optimized c_foreach: only use one iter.
Diffstat (limited to 'include')
| -rw-r--r-- | include/stc/ccommon.h | 7 | ||||
| -rw-r--r-- | include/stc/cdeq.h | 2 |
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; } |
