Prevent unneeded memory allocation in Strgrow

This commit is contained in:
Tatsuya Kinoshita
2021-03-04 07:03:18 +09:00
parent 25252e64e4
commit 91731ec385

4
Str.c
View File

@@ -288,14 +288,16 @@ Strgrow(Str x)
if (x->length + 1 >= newlen)
x->length = newlen - 2;
}
if (x->area_size < newlen) {
x->ptr = GC_MALLOC_ATOMIC(newlen);
if (x->ptr == NULL)
exit(1);
x->area_size = newlen;
bcopy((void *)old, (void *)x->ptr, x->length);
x->ptr[x->length] = '\0';
GC_free(old);
}
x->ptr[x->length] = '\0';
}
Str
Strsubstr(Str s, int beg, int len)