summaryrefslogtreecommitdiff
path: root/libguile/strings.c
diff options
context:
space:
mode:
authorMark H Weaver <mhw@netris.org>2012-01-10 10:13:43 -0500
committerMark H Weaver <mhw@netris.org>2012-01-10 10:13:43 -0500
commit69cd5299e308571149d15eac774ee23fc97ecb0e (patch)
tree6fed5d5d02bbb85c6b8b4001abd3c8b6e36a8a3e /libguile/strings.c
parent17bec5451bfb14c1412669a40b78e483dfe56933 (diff)
downloadguile-69cd5299e308571149d15eac774ee23fc97ecb0e.tar.gz
Use a common null stringbuf in `scm_i_make_string'
* libguile/strings.c (scm_i_make_string): Use a common null stringbuf for newly-allocated empty strings.
Diffstat (limited to 'libguile/strings.c')
-rw-r--r--libguile/strings.c16
1 files changed, 15 insertions, 1 deletions
diff --git a/libguile/strings.c b/libguile/strings.c
index 5dcb321e4..8491b1ea2 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -267,8 +267,22 @@ SCM scm_nullstr;
SCM
scm_i_make_string (size_t len, char **charsp, int read_only_p)
{
- SCM buf = make_stringbuf (len);
+ static SCM null_stringbuf = SCM_BOOL_F;
+ SCM buf;
SCM res;
+
+ if (len == 0)
+ {
+ if (SCM_UNLIKELY (scm_is_false (null_stringbuf)))
+ {
+ null_stringbuf = make_stringbuf (0);
+ SET_STRINGBUF_SHARED (null_stringbuf);
+ }
+ buf = null_stringbuf;
+ }
+ else
+ buf = make_stringbuf (len);
+
if (charsp)
*charsp = (char *) STRINGBUF_CHARS (buf);
res = scm_double_cell (read_only_p ? RO_STRING_TAG : STRING_TAG,