From 435fd25e5c74aea72eb20f4007977183cdbe0919 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 6 Oct 2021 16:08:08 +0200 Subject: Some while to for changed. Return value for cstack_X_push/emplace. Docs updated. --- include/stc/cdeq.h | 6 +++--- include/stc/cstack.h | 9 +++++---- include/stc/cvec.h | 6 +++--- 3 files changed, 11 insertions(+), 10 deletions(-) (limited to 'include') diff --git a/include/stc/cdeq.h b/include/stc/cdeq.h index f31000db..01590f47 100644 --- a/include/stc/cdeq.h +++ b/include/stc/cdeq.h @@ -319,7 +319,7 @@ cx_memb(_insert_range_p)(Self* self, cx_value_t* pos, const cx_value_t* p1, const cx_value_t* p2, bool clone) { pos = cx_memb(_insert_space_)(self, pos, p2 - p1); cx_iter_t it = {pos}; - if (clone) while (p1 != p2) { *pos++ = i_valfrom(i_valto(p1)); ++p1; } + if (clone) for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1)); else memcpy(pos, p1, (p2 - p1)*sizeof *p1); return it; } @@ -328,7 +328,7 @@ STC_DEF cx_iter_t cx_memb(_emplace_range_p)(Self* self, cx_value_t* pos, const cx_rawvalue_t* p1, const cx_rawvalue_t* p2) { pos = cx_memb(_insert_space_)(self, pos, p2 - p1); cx_iter_t it = {pos}; - while (p1 != p2) { *pos++ = i_valfrom(*p1); ++p1; } + for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1); return it; } @@ -337,7 +337,7 @@ cx_memb(_erase_range_p)(Self* self, cx_value_t* p1, cx_value_t* p2) { size_t n = p2 - p1; if (n > 0) { cx_value_t* p = p1, *end = self->data + cdeq_rep_(self)->size; - while (p != p2) { i_valdel(p); ++p; } + for (; p != p2; ++p) i_valdel(p); if (p1 == self->data) self->data += n; else memmove(p1, p2, (end - p2) * sizeof(i_val)); cdeq_rep_(self)->size -= n; diff --git a/include/stc/cstack.h b/include/stc/cstack.h index 7bc0f3fb..00d99fa1 100644 --- a/include/stc/cstack.h +++ b/include/stc/cstack.h @@ -83,13 +83,14 @@ STC_INLINE void cx_memb(_reserve)(Self* self, size_t n) { STC_INLINE void cx_memb(_shrink_to_fit)(Self* self) { cx_memb(_reserve)(self, self->size); } -STC_INLINE void cx_memb(_push)(Self* self, cx_value_t val) { +STC_INLINE cx_value_t* cx_memb(_push)(Self* self, cx_value_t val) { if (self->size == self->capacity) cx_memb(_reserve)(self, self->size*3/2 + 4); - self->data[ self->size++ ] = val; + cx_value_t* vp = self->data + self->size++; + *vp = val; return vp; } -STC_INLINE void cx_memb(_emplace)(Self* self, cx_rawvalue_t raw) - { cx_memb(_push)(self, i_valfrom(raw)); } +STC_INLINE cx_value_t* cx_memb(_emplace)(Self* self, cx_rawvalue_t raw) + { return cx_memb(_push)(self, i_valfrom(raw)); } STC_INLINE Self cx_memb(_clone)(Self v) { Self out = {(cx_value_t *) c_malloc(v.size*sizeof(cx_value_t)), v.size, v.size}; diff --git a/include/stc/cvec.h b/include/stc/cvec.h index 745411fc..c6dcb147 100644 --- a/include/stc/cvec.h +++ b/include/stc/cvec.h @@ -309,7 +309,7 @@ cx_memb(_insert_range_p)(Self* self, cx_value_t* pos, const cx_value_t* p1, const cx_value_t* p2, bool clone) { pos = cx_memb(_insert_space_)(self, pos, p2 - p1); cx_iter_t it = {pos}; - if (clone) while (p1 != p2) { *pos++ = i_valfrom(i_valto(p1)); ++p1; } + if (clone) for (; p1 != p2; ++p1) *pos++ = i_valfrom(i_valto(p1)); else memcpy(pos, p1, (p2 - p1)*sizeof *p1); return it; } @@ -319,7 +319,7 @@ cx_memb(_emplace_range_p)(Self* self, cx_value_t* pos, const cx_rawvalue_t* p1, const cx_rawvalue_t* p2) { pos = cx_memb(_insert_space_)(self, pos, p2 - p1); cx_iter_t it = {pos}; - while (p1 != p2) { *pos++ = i_valfrom(*p1); ++p1; } + for (; p1 != p2; ++p1) *pos++ = i_valfrom(*p1); return it; } @@ -328,7 +328,7 @@ cx_memb(_erase_range_p)(Self* self, cx_value_t* p1, cx_value_t* p2) { intptr_t len = p2 - p1; if (len > 0) { cx_value_t* p = p1, *end = self->data + cvec_rep_(self)->size; - while (p != p2) { i_valdel(p); ++p; } + for (; p != p2; ++p) i_valdel(p); memmove(p1, p2, (end - p2) * sizeof(i_val)); cvec_rep_(self)->size -= len; } -- cgit v1.2.3