[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Guile-commits] 01/01: Minor make-string optimization
From: |
Andy Wingo |
Subject: |
[Guile-commits] 01/01: Minor make-string optimization |
Date: |
Fri, 17 Feb 2017 05:30:10 -0500 (EST) |
wingo pushed a commit to branch master
in repository guile.
commit 9ee21f3e97ae65b79a861d076e3ea8f73508bda8
Author: Andy Wingo <address@hidden>
Date: Fri Feb 17 11:29:31 2017 +0100
Minor make-string optimization
* libguile/strings.c (STRINGBUF_SET_MUTABLE): New helper.
(scm_i_string_ensure_mutable_x): Use new helper.
(scm_make_string): Mark stringbuf as mutable.
---
libguile/strings.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/libguile/strings.c b/libguile/strings.c
index e460a93..8d0aa45 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -83,6 +83,10 @@ SCM_SYMBOL (sym_error, "error");
#define STRINGBUF_WIDE(buf) (SCM_CELL_WORD_0(buf) & STRINGBUF_F_WIDE)
#define STRINGBUF_MUTABLE(buf) (SCM_CELL_WORD_0(buf) & STRINGBUF_F_MUTABLE)
+
+#define STRINGBUF_SET_MUTABLE(buf) \
+ SCM_SET_CELL_WORD_0 (buf, SCM_CELL_WORD_0 (buf) | STRINGBUF_F_MUTABLE)
+
#define STRINGBUF_CONTENTS(buf) ((void *) \
SCM_CELL_OBJECT_LOC (buf, \
STRINGBUF_HEADER_SIZE))
@@ -433,8 +437,7 @@ scm_i_string_ensure_mutable_x (SCM str)
memcpy (STRINGBUF_CHARS (new_buf), STRINGBUF_CHARS (buf), len);
}
- SCM_SET_CELL_WORD_0 (new_buf,
- SCM_CELL_WORD_0 (new_buf) | STRINGBUF_F_MUTABLE);
+ STRINGBUF_SET_MUTABLE (new_buf);
SET_STRING_STRINGBUF (str, new_buf);
}
}
@@ -1119,7 +1122,12 @@ SCM_DEFINE (scm_make_string, "make-string", 1, 1, 0,
"of the string are all set to @code{#\nul}.")
#define FUNC_NAME s_scm_make_string
{
- return scm_c_make_string (scm_to_size_t (k), chr);
+ SCM ret = scm_c_make_string (scm_to_size_t (k), chr);
+ /* Given that make-string is mostly used by Scheme to prepare a
+ mutable string buffer, let's go ahead and mark this as mutable to
+ avoid a copy when this buffer is next written to. */
+ STRINGBUF_SET_MUTABLE (STRING_STRINGBUF (ret));
+ return ret;
}
#undef FUNC_NAME