diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2025-01-29 20:34:26 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2025-01-29 20:34:26 -0800 |
commit | e068f31a5eb62c12a55f847db5b8ba2b88e36d05 (patch) | |
tree | 56db90fc431f46238669845970b0cbccf054b48c | |
parent | f8658bd4898f415de90f50121afe42a6cad50910 (diff) | |
download | txr-e068f31a5eb62c12a55f847db5b8ba2b88e36d05.tar.gz txr-e068f31a5eb62c12a55f847db5b8ba2b88e36d05.tar.bz2 txr-e068f31a5eb62c12a55f847db5b8ba2b88e36d05.zip |
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.
-rw-r--r-- | lib.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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; } |