diff options
author | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
---|---|---|
committer | Nicholas <nbnoll@eml.cc> | 2021-11-12 09:22:01 -0800 |
commit | ce05175372a9ddca1a225db0765ace1127a39293 (patch) | |
tree | 5988b4d4f6b402e4953945886fc90aae11203df6 /sys/base/string/grow.c | |
parent | b375f3cdedb5b0e08745d100b40e38d2f8396a58 (diff) |
chore: simplified organizational structurelaptop
Diffstat (limited to 'sys/base/string/grow.c')
-rw-r--r-- | sys/base/string/grow.c | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/sys/base/string/grow.c b/sys/base/string/grow.c deleted file mode 100644 index 39a9d2f..0000000 --- a/sys/base/string/grow.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "internal.h" - -// grow ensures that the string can encompass at least delta bytes. -// if it already can, this is a no op. -// if it can't, the string will be reallocated. -void -str·grow(string *s, vlong delta) -{ - Hdr *h, *newh; - vlong cap = str·cap(*s); - vlong len = str·len(*s); - assert(cap >= len); // To prevent unsigned behavior - - if (cap - len >= delta) return; - - h = (Hdr*)(*s - sizeof(Hdr)); - - vlong newCap = cap + delta; - assert(newCap >= cap); // To prevent unsigned behavior - if (newCap < MAX_STRING_ALLOC) { - newCap *= 2; - } else - newCap += MAX_STRING_ALLOC; - - newh = (Hdr*)realloc(h, sizeof(*h) + newCap + 1); - if (newh == nil) return; - - memset(newh->buf + len, '\0', newCap - len); - newh->cap = newCap; - newh->len = len; - - *s = newh->buf; -} |