Only realloc once when appending string to stringbuilder
This commit is contained in:
parent
22453f42e6
commit
a961def84a
@ -111,9 +111,11 @@ static inline void pushStringBuilder(struct StringBuilder * sb, char c) {
|
||||
}
|
||||
|
||||
static inline void pushStringBuilderStr(struct StringBuilder * sb, char *str, size_t len) {
|
||||
while (sb->capacity < sb->length + len) {
|
||||
size_t old = sb->capacity;
|
||||
sb->capacity = GROW_CAPACITY(old);
|
||||
if (sb->capacity < sb->length + len) {
|
||||
while (sb->capacity < sb->length + len) {
|
||||
size_t old = sb->capacity;
|
||||
sb->capacity = GROW_CAPACITY(old);
|
||||
}
|
||||
sb->bytes = realloc(sb->bytes, sb->capacity);
|
||||
}
|
||||
for (size_t i = 0; i < len; ++i) {
|
||||
|
Loading…
Reference in New Issue
Block a user