From c56fb2bc7b8d39f45410a36a1b623baf10178eb9 Mon Sep 17 00:00:00 2001 From: Tyge Løvset Date: Wed, 25 May 2022 20:18:43 +0200 Subject: Fixed #25: "behaviour of cstr_clear is suprising": Resets size to 0, while keeping current allocation. --- include/stc/cstr.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'include') diff --git a/include/stc/cstr.h b/include/stc/cstr.h index 41479c30..ca6d9392 100644 --- a/include/stc/cstr.h +++ b/include/stc/cstr.h @@ -145,11 +145,6 @@ STC_INLINE void cstr_drop(cstr* self) { cstr_l_drop(self); } -STC_INLINE void cstr_clear(cstr* self) { - cstr_drop(self); - cstr_s_set_size(self, 0); -} - #define SSO_CALL(s, call) (cstr_is_long(s) ? cstr_l_##call : cstr_s_##call) STC_INLINE void _cstr_set_size(cstr* self, size_t len) @@ -173,6 +168,9 @@ STC_INLINE size_t cstr_length(cstr s) STC_INLINE size_t cstr_capacity(cstr s) { return cstr_is_long(&s) ? cstr_l_cap(&s) : cstr_s_cap; } +STC_INLINE void cstr_clear(cstr* self) + { _cstr_set_size(self, 0); } + STC_INLINE char* cstr_expand_uninit(cstr *self, size_t n) { size_t len = cstr_size(*self); char* d; if (!(d = cstr_reserve(self, len + n))) return NULL; -- cgit v1.2.3