From e068f31a5eb62c12a55f847db5b8ba2b88e36d05 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Wed, 29 Jan 2025 20:34:26 -0800 Subject: mkstring: minimum 7 char alloc size. * lib.c (mkstring): Do not allocate less than 8 characters, including null terminator, to the string. This speeds up code which builds up strings from empty, one character at a time. --- lib.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib.c b/lib.c index ff9ec00b..4f5cb11d 100644 --- a/lib.c +++ b/lib.c @@ -5285,13 +5285,14 @@ val mkstring(val len, val ch_in) (uw_throwf(range_error_s, lit("~a: negative size ~s specified"), self, len, nao), 0), c_num(len, self)); - wchar_t *str = chk_wmalloc(l + 1); + size_t a = max(7, l); + wchar_t *str = chk_wmalloc(a + 1); val s = string_own(str); val ch = default_arg_strict(ch_in, chr(' ')); wmemset(str, c_chr(ch), l); str[l] = 0; s->st.len = len; - s->st.alloc = c_num(len, self) + 1; + s->st.alloc = a; return s; } -- cgit v1.2.3