summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-05-25 20:18:43 +0200
committerTyge Løvset <[email protected]>2022-05-25 20:18:43 +0200
commitc56fb2bc7b8d39f45410a36a1b623baf10178eb9 (patch)
treee0899cc4963713a3ba74afc06180542827438ccc /include
parentae77114308c50ac88d608d4ea145bbcbeb130081 (diff)
downloadSTC-modified-c56fb2bc7b8d39f45410a36a1b623baf10178eb9.tar.gz
STC-modified-c56fb2bc7b8d39f45410a36a1b623baf10178eb9.zip
Fixed #25: "behaviour of cstr_clear is suprising": Resets size to 0, while keeping current allocation.
Diffstat (limited to 'include')
-rw-r--r--include/stc/cstr.h8
1 files changed, 3 insertions, 5 deletions
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;